Java program to check whether a character is alphabet or not













Java program to check whether a character is alphabet or not

Java Tutorial Java Exercises Data Structures











Java program to check whether a character is alphabet or not


/** * Java program to check whether a character is alphabet or not */ import java.util.Scanner; public class Test { public static void main(String args[]) { char ch; Scanner op=new Scanner(System.in); /* Input a character from user */ System.out.print("Enter any character: "); ch=op.next().charAt(0); if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) { System.out.println("Character is an ALPHABET."); } else { System.out.println("Character is NOT ALPHABET."); } } }




Output:

Enter any character: 8 Character is NOT ALPHABET. Enter any character: p Character is an ALPHABET.