Write code to implement the toLowerCase(char ch)
method
In this step, you will write the code to implement the toLowerCase(char ch)
method. The method takes a character as input and returns the corresponding lowercase character if it is an uppercase character, otherwise, it returns the same character.
public class CharacterToLowerCase {
public static void main(String[] args) {
// create a character variable
char ch = 'F';
// convert the character to lowercase using toLowerCase(char ch) method
char lowerCaseCh = Character.toLowerCase(ch);
// print the original and lowercase character
System.out.println("Original character: " + ch);
System.out.println("Lowercase character: " + lowerCaseCh);
}
}
In the above code, we first create a char
variable ch
and set its value to 'F'
. Then, we use the toLowerCase(char ch)
method to convert this character to lowercase and store the result in another char
variable lowerCaseCh
. Finally, we print out both the original and lowercase characters.