How to check whether a character is alphabet or not in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'z';

        if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
            System.out.println(ch + " is an alphabet");
        else
            System.out.println(ch + " is not an alphabet");
    }
}



/*
run:
 
z is an alphabet
 
*/

 



answered Jan 12, 2022 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'z';

        if (Character.isAlphabetic(ch)) 
            System.out.println(ch + " is an alphabet");
        else
            System.out.println(ch + " is not an alphabet");
    }
}



/*
run:
 
z is an alphabet
 
*/

 



answered Jan 12, 2022 by avibootz

Related questions

...