Java program to find whether the given character is an alphabet or not

Java Programming Java8Object Oriented Programming

Read a character from user verify whether it lies between a and z (both small and capital). If it does it is an alphabet.

Example

import java.util.Scanner;
public class AlphabetOrNot {
   public static void main(String args[]){
      System.out.println("Enter a character :: ");
      Scanner sc = new Scanner(System.in);
      char ch = sc.next().charAt(0);

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

Output

Enter a character ::
d
Given character is an alphabet
raja
Published on 26-Apr-2018 08:00:28
Advertisements