Coding Practice

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

Check whether a character is alphabet or not
Sample Output
Check whether a character is alphabet or not.

Enter a character: 9
9 is not an alphabet.
Java-Source Code
//package ifelsejava;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        char ch;

        Scanner input = new Scanner(System.in);

        System.out.println("Check whether a character is alphabet or not.\n");

        System.out.print("Enter a character: ");
        ch = input.next().charAt(0);

        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.");
            
        }
    }
}
Sample Output
Check whether a character is alphabet or not.

Enter a character: R
R is an alphabet.

No comments:

Post a Comment

Change Theme
X