Skip to content

Commit d8bfb2a

Browse files
committed
feat: Add character case check using Character class utilities
🧠 Logic: - Accepts a single character input - Checks if it's a letter using `Character.isLetter()` - Determines case using `Character.isLowerCase()` - Outputs whether it's lowercase, uppercase, or not a letter. Signed-off-by: Somesh diwan <[email protected]>
1 parent 352a057 commit d8bfb2a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Section7ConditionalStatements/Practice/src/CaseCheck.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
public class CaseCheck {
44
public static void main(String[] args) {
55
Scanner in = new Scanner(System.in);
6-
char ch = in.next().trim().charAt(0);
6+
System.out.print("Enter a character: ");
77

8-
if (ch >= 'a' && ch <= 'z') {
9-
System.out.println("Lowercase");
8+
char ch = in.next().trim().charAt(0);
9+
10+
if (Character.isLetter(ch)) {
11+
if (Character.isLowerCase(ch)) {
12+
System.out.println("'" + ch + "' is Lowercase");
13+
} else {
14+
System.out.println("'" + ch + "' is Uppercase");
15+
}
1016
} else {
11-
System.out.println("Uppercase");
17+
System.out.println("'" + ch + "' is not a letter");
1218
}
13-
19+
in.close();
1420
}
1521
}

0 commit comments

Comments
 (0)