In this step, we will learn how to use the %S
and %s
conversion characters to format strings in uppercase and lowercase, respectively.
- Open the
SimpleFormatExample.java
file in an editor.
- Modify the formatting string to include a string using the
%S
conversion character to format the string in uppercase.
- Modify the formatting string to include a second string using the
%s
conversion character to format the string in lowercase.
- Save and close the
SimpleFormatExample.java
file.
- In the terminal, compile the
SimpleFormatExample.java
file by running the following command: javac SimpleFormatExample.java
.
- Then, run the class file using the command
java SimpleFormatExample
.
Here is the modified code:
public class SimpleFormatExample {
public static void main(String[] args) {
String formattedString = String.format("The word %S is in uppercase and %s is in lowercase", "HELLO", "world");
System.out.println(formattedString);
}
}
When you run the code, you should see the following output:
The word HELLO is in uppercase and world is in lowercase