- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStringLowerExample.java
More file actions
Latest commit
35 lines (25 loc) · 808 Bytes
/
Copy pathStringLowerExample.java
File metadata and controls
35 lines (25 loc) · 808 Bytes
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
importjava.util.Scanner;
/**
* 33. How to convert all char in string lower case in java Program.
*/
publicclassStringLowerExample {
publicstaticvoidmain(String[] args) {
try (Scannerscan = newScanner(System.in)) {
System.out.println("=== String Lower Case Program ===");
while (true) {
System.out.print("\nEnter a sentence (type 'exit' to quit): ");
Stringinput = scan.nextLine();
// Exit condition
if (input.equalsIgnoreCase("exit")) {
System.out.println("Program terminated.");
break;
}
// Trim and convert to lowercase
StringlowerCase = input.trim().toLowerCase();
System.out.println("Lowercase sentence: " + lowerCase);
}
} catch (Exceptione) {
System.out.println("Unexpected error occurred: " + e.getMessage());
}
}
}