Write a Program to find char digit number and special char in java.



import java.util.Scanner;

public class Demo {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Enter a char");

char c = s.next().charAt(0);

if (Character.isDigit(c)) {

System.out.println("Digit");

} else if (Character.isLetter(c)) {

System.out.println("Char");

} else if (Character.isSpaceChar(c)) {

System.out.println("Empty");

} else {

System.out.println("Special char");

}

}

}

No comments: