Ssup2 Blog logo Ssup2 Blog

Problem

Solution 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
    public String toLowerCase(String str) {
        char[] charArry = str.toCharArray();
        for (int i = 0; i < charArry.length; i++) {
            charArry[i] = getLower(charArry[i]);
        }
        return new String(charArry);
    }
    
    private boolean isUpper(char c) {
        return (c >= 'A') && (c <= 'Z');
    }
    
    private char getLower(char c) {
        if (isUpper(c)) {
            return (char)((c - 'A') + 'a');
        } else {
            return c;
        }
    }
}
Solution 1