This tutorial provides Java Program to Check Whether a Character is Alphabet or Not.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import java.util.Scanner; public class AlphabetFinder { public static void main(String args[]) { char character; Scanner scanner = new Scanner(System.in); System.out.print("Enter a Character : "); character = scanner.next().charAt(0); if((character>='a' && character<='z') || (character>='A' && character<='Z')){ System.out.print(character + " is an alphabet."); }else{ System.out.print(character + " is not an alphabet."); } } } |
Output:
Enter a Character : d
d is an alphabet.
d is an alphabet.
The ASCII value of lowercase alphabets range from 97 to 122. And, the ASCII value of uppercase alphabets range from 65 to 90.
That’s why, we compared variable character between ‘a’ (97) to ‘z’ (122) for lowercase character and between ‘A’ (65) to ‘Z’ (90) for uppercase character.
That’s all about Java Program to Check Whether a Character is Alphabet or Not.
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.