Question:Â
Write a java program that performs an action to check your input is Alphabet or not? you have to ask the user to enter a character and check Alphabet. Alphabet range is a-z & A-Z otherwise it’s not an Alphabet like output sample.
 Output Sample:  Â
1 2 3 4 5 6 7 8 |
Enter a Input: a a is an Alphabet! Enter a Input: Z Z is an Alphabet! Enter a Input: 5 5 is not an Alphabet! |
 Source Code:Â
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Scanner; public class Alphabet { public static void main(String[] args) { //variable initialization char input; //input from the user Scanner sc = new Scanner(System.in); System.out.print("Enter a Input: "); input = sc.next().charAt(0); //calculate Alphabet or not & print the output if((input >= 'a' && input <= 'z') || (input >= 'A' && input <= 'Z')){ System.out.println(input + " is an Alphabet!"); }else{ System.out.println(input + " is not an Alphabet!"); } } } |