(Easy) To Lower Case LeetCode

Description

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

Example 1:

Input: "Hello"
Output: "hello"

Example 2:

Input: "here"
Output: "here"

Example 3:

    Input: "LOVELY

   Output: "lovely"

Solution

class Solution {
    public String toLowerCase(String str) {
        String output = "";
        
        for(int i = 0; i< str.length(); i++){
            
            if((int)str.charAt(i)>=65 && (int)str.charAt(i)<=90){
                
                output = output+ (char)(str.charAt(i)+32);
                
            }
            
            else{
                
                output = output+str.charAt(i);
            }
        }
        
        return output;
        
    }
}

 

猜你喜欢

转载自www.cnblogs.com/codingyangmao/p/11273407.html