[leetcode] problem 709 – to lower case

Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.

Example

No.1

Input: “Hello”

Output: “hello”

No.2

Input: “here”

Output: “here”

No.3

Input: “LOVELY”

Output: “lovely”

Code

1
2
3
4
5
6
7
8
9
10
public String (String str) {
char[] ch = str.toCharArray();

for (int i = 0; i < ch.length; i++) {
if (ch[i] >= 'A' && ch[i] <= 'Z')
ch[i] -= 'A' - 'a';
}

return String.valueOf(ch);
}