In this tutorial, I will show you guys how to create a Java program to ask the user to give a character, and then the program will check if the given character is an alphabet or not.
Program Listing
/**
* @author Jake Rodriguez Pomperada,MAED-IT, MIT
* www.jakerpomperada.com www.jakerpompomperada.blogspot.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental Philippines
*
*/
import java.util.Scanner;
public class Alphabet_Checker {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
System.out.println();
System.out.println("===== Alphabet Checker in Java =====");
System.out.println();
System.out.print("Give a Alphabet : ");
char char_given = scan.next().charAt(0);
System.out.println();
// checks if char_giv is an alphabet
if (Character.isAlphabetic(char_given)) {
System.out.println("The given " + char_given + " is an alphabet.");
}
else {
System.out.println("The given " + char_given + " is not an alphabet.");
}
System.out.println();
System.out.println("===== END OF PROGRAM =====");
System.out.println();
}
}
No comments:
Post a Comment