write a program in java to check whether the entered data is alphabet or digit. if it is alphabet .then print whether it is capital or small case. If digit is entered, throw user defined exception 'digit not allowed'.
Answers
Answered by
1
import java.util.Scanner;
public class InputChecker {
public static void main(String[ ] args) {
System.out.print("Enter data - ");
char data = new Scanner(System.in).next( ).charAt(0);
if (Character.isLetter(data))
System.out.println("It is in "
+ (Character.isLowerCase(data) ? "Lowercase" : "Uppercase"));
else if (Character.isDigit(data))
try {
throw new DigitNotAllowed( );
} catch (DigitNotAllowed ignored) { }
else System.out.println("Special Character");
}
private static class DigitNotAllowed extends Throwable {
DigitNotAllowed( ) {
System.out.println("Digit not allowed!");
}
}
}
Similar questions
English,
2 months ago
Math,
2 months ago
Science,
2 months ago
English,
4 months ago
Chemistry,
10 months ago
Computer Science,
10 months ago
Computer Science,
10 months ago