Alphabets range from A-Z and a-z. With this logic, we can specify our condition. And with the condition, we can determine if a certain character, a number, punctuation mark, escape character or sequence, and so on, is an alphabet.
if((character>='a' && character<='z') || (character>='A' && character<='Z'))
The character
contains the character we want to check.
Let's look at the code below:
class HelloWorld {public static void main( String args[] ) {//create and initialize variables.char ch1 = '@';char ch2 = '#';char ch3 = 'e';char ch4 = 'L';// check if alphabetscheckIfAlphabet(ch1);checkIfAlphabet(ch2);checkIfAlphabet(ch3);checkIfAlphabet(ch4);}static void checkIfAlphabet(char ch){//condition for checking characters.if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z')){System.out.print(ch + " is an Alphabet\n");}else{System.out.print(ch + " is not an Alphabet\n");}}}
checkIfAlphabet()
to check if the characters we pass are alphabets or not.checkIfAlphabet()
function that takes a character and checks if it is an alphabet using the specified condition.