37. JAVA Program To Check Character is Lowercase or Uppercase or Sepecial Character using switch case
How does this program work?
- This program is used to compare the given Character.
- Here we use the "char" to store the user input.
- By comparing the given input using switch case. we get the output.
Here is the code
//Checking the input letter is uppercase or lowercase using switch case
import java.util.Scanner;public class character
{
public static void main(String args[])
{
char ch;
System.out.println("Enter a character:");
Scanner sc = new Scanner(System.in);
ch = sc.next().charAt(0);
if(ch >= 'A' && ch <= 'Z')
{
ch = 1;
}
else
if(ch >= 'a' && ch <= 'z')
{
ch = 2;
}
else
if(ch >= '0' && ch <= '9')
{
ch = 3;
}
switch(ch)
{
case 1:
System.out.println("Upper case character\n");
break;
case 2:
System.out.println("lower case character\n");
break;
case 3:
System.out.println("Digit \n");
break;
default:
System.out.println("Special character\n");
}
}
}