实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。
示例 1:
输入: "Hello"输出: "hello"
示例 2:
输入: "here"输出: "here"
示例** 3:**
输入: "LOVELY"输出: "lovely"
+32
转换为小写,为小写则不作处理;resultStr
;resultStr
;package string;
/**
* Created with IntelliJ IDEA.
* Version : 1.0
* Author : cunyu
* Email : cunyu1024@foxmail.com
* Website : https://cunyu1943.github.io
* Date : 2020/4/3 17:45
* Project : LeetCode
* Package : string
* Class : SevenZeroNight
* Desc :
*/
public class SevenZeroNight {
public static void main(String[] args) throws Exception {
String str = "Hello World!";
SevenZeroNight sevenZeroNight = new SevenZeroNight();
System.out.println(sevenZeroNight.toLowerCase(str));
}
public String toLowerCase(String str) {
String resultStr = "";
for (int i = 0; i < str.length(); i++) {
int ch = (int) str.charAt(i);
if ((int) ch >= 65 && (int) ch <= 90) {
ch += 32;
}
resultStr += "" + (char) ch;
}
return resultStr;
}
}
[1]
709. 转换成小写字母: https://leetcode-cn.com/problems/to-lower-case/