I ran your code just as it is, and it printed it both in uppercase and lowercase, but I noticed you had a comment that said //Display the first character
, and following it, keyboard.next()
. This was the only incorrect part. To print the first letter of a string(in this case the string is city
), use this line: System.out.println(city.substring(0,1).toUpperCase());
below is an example of the output:
Enter favorite city: dallas.
String Length :6
DALLAS
dallas
D
4
solved string.toUpperCase() and string.toLowercase() not printing [closed]