Q:

Java program to check whether a given character is alphabet or not

belongs to collection: Java Basic Programs

0

Given a character and we have to check whether it is an alphabet or not?

Example 1:

Input:
Enter a character: A
Output:
A is an alphabet 

Example 2:

Input:
Enter a character: @
Output:
@ is not an alphabet 

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to check given character is an alphabet or not in java

import java.util.Scanner;

public class AlphabetOrNot
{
    public static void main(String args[])
    {
    	//create and initialize object.
        char ch;
        Scanner scan = new Scanner(System.in);
		
        //Input character
        System.out.print("Enter a Character : ");
        ch = scan.next().charAt(0);
		
        //condition for checking characters.
        if((ch>='a' && ch<='z') || (ch>='A' && ch<='Z'))
        {
            System.out.print(ch + " is an Alphabet");
        }
        else
        {
            System.out.print(ch + " is not an Alphabet");
        }
    }
}

Output

First run:
Enter a Character : A
A is an Alphabet

Second run:
Enter a Character : @
@ is not an Alphabet

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to print pattern of numbers in triang... >>
<< Java program to print spiral pattern of the given ...