If I run this simple code, the output I get is an integer value anyone know why?
I’m trying to print first character of the first name and the first five character of the last name concatenated together.
Scanner scan = new Scanner (System.in);
String firstName, lastName;
System.out.print ("Enter First Name: ");
firstName = scan.nextLine();
System.out.print ("\n");
System.out.print ("Enter Last Name: ");
lastName = scan.nextLine();
System.out.println (firstName.charAt(0)+lastName.charAt(0));
When you call
you end up calling System.out.println(int) due to the addition of the character values themselves yielding an integer value.
You could use: