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


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

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 13-Mar-2020

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements