Write a short program to find whether the given character is a digit or a letter.
Java Programming Language Decision Making in java (Article) Decision Making in java (Program)
9
Given Input:
Enter a character: A
Expected Output:
It is a Letter.
Given Input:
Enter a character: 7
Expected Output:
It is a Digit.
Program:
import java.util.Scanner;
public class CheckCharacter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = sc.next().charAt(0);
if (Character.isDigit(ch)) {
System.out.println("It is a Digit.");
}
else if (Character.isLetter(ch)) {
System.out.println("It is a Letter.");
}
else {
System.out.println("It is neither a Digit nor a Letter.");
}
sc.close();
}
}
Output:
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.
It is a Letter.
Given Input:
Enter a character: 7
Expected Output:
It is a Digit.
Program:
import java.util.Scanner;
public class CheckCharacter {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = sc.next().charAt(0);
if (Character.isDigit(ch)) {
System.out.println("It is a Digit.");
}
else if (Character.isLetter(ch)) {
System.out.println("It is a Letter.");
}
else {
System.out.println("It is neither a Digit nor a Letter.");
}
sc.close();
}
}
Output:
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.
It is a Digit.
Program:
import java.util.Scanner; public class CheckCharacter { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a character: "); char ch = sc.next().charAt(0); if (Character.isDigit(ch)) { System.out.println("It is a Digit."); } else if (Character.isLetter(ch)) { System.out.println("It is a Letter."); } else { System.out.println("It is neither a Digit nor a Letter."); } sc.close(); } }
Output:
This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.