問題: Implement function ToLowerCase() that has a string parameter str, and returns the same string in lowercase.git
方法: 這個應該不用說了吧,直接看代碼。github
具體實現:bash
class ToLowerCase {
fun toLowerCase(str: String): String {
val result = StringBuilder()
for(ch in str) {
if (ch in 'A'..'Z') {
result.append(ch + ('a' - 'A') )
} else {
result.append(ch)
}
}
return result.toString()
}
}
fun main(args: Array<String>) {
val input = "Hello"
val toLowerCase = ToLowerCase()
print(toLowerCase.toLowerCase(input))
}
複製代碼
有問題隨時溝通app