mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-19 17:54:42 +08:00
Resolve build errors & cleanup structure (#2334)
This commit is contained in:
28
Strings/Lower.java
Normal file
28
Strings/Lower.java
Normal file
@ -0,0 +1,28 @@
|
||||
package Strings;
|
||||
|
||||
public class Lower {
|
||||
|
||||
/** Driver Code */
|
||||
public static void main(String[] args) {
|
||||
String[] strings = {"ABC", "ABC123", "abcABC", "abc123ABC"};
|
||||
for (String s : strings) {
|
||||
assert toLowerCase(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.
|
||||
*/
|
||||
public static String toLowerCase(String s) {
|
||||
char[] values = s.toCharArray();
|
||||
for (int i = 0; i < values.length; ++i) {
|
||||
if (Character.isLetter(values[i]) && Character.isUpperCase(values[i])) {
|
||||
values[i] = Character.toLowerCase(values[i]);
|
||||
}
|
||||
}
|
||||
return new String(values);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user