-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacterIdentity.java
48 lines (37 loc) · 1.43 KB
/
CharacterIdentity.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CharacterIdentity {
public static void main(String[] args) {
//initiation of variable 'userInput'
String userInput = "";
//initiation of variable 'charClass'
String charClass = "";
//
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try {
userInput = reader.readLine();
}
// if the user input is invalid then an error message is displayed
catch (IOException ex) {
System.err.print("Input error!");
ex.printStackTrace();
System.exit(1);
}
//for loop that iterates the length of the users input
for (int i = 0; i < userInput.length(); ++i) {
//The charAt() method returns the character at the specified index in a string.
char c = userInput.charAt(i);
//checks whether character is uppercase
if (Character.isUpperCase(c)){
System.out.println(c+" : uppercase");
//checks whether character is lowercase
}else if (Character.isLowerCase(c)){
System.out.println(c+" : lowercase");
//checks whether character is numeric
}else if (Character.isDigit(c)){
System.out.println(c+" : numeric");
}
}
}
}