How to check uppercase and lowercase in Java code example
Example 1: java how to make a string lowercase
public class CaseDemonstration {
public static void main(String[] args) {
String testString = "THIS IS AN EXAMPLE OF A STRING";
String testStringLower = testString.toLowerCase();
System.out.println(testStringLower);
String testStringUpper = testStringLower.toUpperCase();
System.out.println(testStringUpper);
}
}
Example 2: write a program to check whether the character is in lowercase or uppercase in java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Alphabet_Check {
public static void main(String args[]) throws IOException{
char m;
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter any alphabet:");
m = (char) bf.read();
if(m >= 97 && m <= 123){
System.out.println("Lower Case");
}
else if(m >= 65 && m <= 96){
System.out.println("Upper Case");
}
else if(m >= 48 && m <= 57){
System.out.println("Digit");
}
}
}
Example 3: char to lowercase java
Character.toLowerCasr(<char need to lower>)
Example 4: java lower case to upper case
toUpperCase()