Title: Convert to lowercase letters
Implements the function ToLowerCase(), which takes a string argument STR, converts the uppercase letters in the string ToLowerCase letters, and returns a new string.Copy the code
Example:
Input: "Hello" output: "Hello" input: "here" output: "here" input: "LOVELY" output: "LOVELY"Copy the code
Think about:
So this is a simple one, just loop through it to see if it's uppercase, just add 32.Copy the code
Implementation:
class Solution { public String toLowerCase(String str) { int num = 'a' - 'A'; char[] array = str.toCharArray(); for (int count = 0; count < str.length(); count++){ if (array[count] >= 'A' && array[count] <= 'Z'){ array[count] += num; } } return new String(array); }}Copy the code