Java program to read a character and check uppercase or Lower Case or Digit or Special Character ?

Yogi Siddeswara 0

Q. Java program to read a character and check below Conditions,
1. Upper Case 
2. Lower Case
3. Digit
4. Special Character


 
  

package impprograms;

import java.util.Scanner;

public class CharType {

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	System.out.println("please enter a character :");
	char ch=sc.next().charAt(0);
	if(ch>=65 && ch<=90) {
		System.out.println("character is Upper Case :"+ ch);
	}
	else if(ch>=97 && ch<=122) {
		System.out.println("character  is lower case :"+ch);
	}
	else if(ch>=48 && ch<=57) {
		System.out.println("Character is Digit"+ch);
	}
	else {System.out.println("character is  Special Character"+ch);}
	
	sc.close();
	}

}
          
(code-box)

Note: you can drag the code workspace to see the complete code

Post a Comment

0 Comments