码迷,mamicode.com
首页 > 其他好文 > 详细

(Easy) To Lower Case LeetCode

时间:2019-07-30 23:18:44      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:bsp   char   length   function   com   str   NPU   ram   img   

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;
        
    }
}

技术图片

 

 

(Easy) To Lower Case LeetCode

标签:bsp   char   length   function   com   str   NPU   ram   img   

原文地址:https://www.cnblogs.com/codingyangmao/p/11273407.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!