Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 21.3k
Expand file tree
/
Copy pathLower.java
More file actions
Latest commit
32 lines (29 loc) · 901 Bytes
/
Copy pathLower.java
File metadata and controls
32 lines (29 loc) · 901 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
packagecom.thealgorithms.strings;
publicfinalclassLower {
privateLower() {
}
/**
* Driver Code
*/
publicstaticvoidmain(String[] args) {
String[] strings = {"ABC", "ABC123", "abcABC", "abc123ABC"};
for (Strings : strings) {
asserttoLowerCase(s).equals(s.toLowerCase());
}
}
/**
* Converts all of the characters in this {@code String} to lower case
*
* @param s the string to convert
* @return the {@code String}, converted to lowercase.
*/
publicstaticStringtoLowerCase(Strings) {
char[] values = s.toCharArray();
for (inti = 0; i < values.length; ++i) {
if (Character.isLetter(values[i]) && Character.isUpperCase(values[i])) {
values[i] = Character.toLowerCase(values[i]);
}
}
returnnewString(values);
}
}