In Java, String objects have built-in methods to change their case:
s.toUpperCase() // converts all characters to uppercase
s.toLowerCase() // converts all characters to lowercase
Here are some examples:
String word = "Hello World";
String upper = word.toUpperCase(); // "HELLO WORLD"
String lower = word.toLowerCase(); // "hello world"
String name = "ALICE";
System.out.println(name.toLowerCase()); // "alice"
These methods return a new String — the original is not modified.
Assignment
Follow the Coding Tutorial and convert word to both uppercase and lowercase!
Hint
Use word.toUpperCase() and word.toLowerCase().
Free plan: 30 tutor messages. PRO is unlimited.
Saved
Ctrl + Enter to check
