编写 toLower / toUppercase 函数的解决方法取决于具体的编程语言。以下是一些常见编程语言的示例代码:
public class StringUtils {
public static String toLowercase(String input) {
return input.toLowerCase();
}
public static String toUppercase(String input) {
return input.toUpperCase();
}
public static void main(String[] args) {
String str = "Hello World";
System.out.println(toLowercase(str)); // 输出 "hello world"
System.out.println(toUppercase(str)); // 输出 "HELLO WORLD"
}
}
def to_lowercase(input):
return input.lower()
def to_uppercase(input):
return input.upper()
str = "Hello World"
print(to_lowercase(str)) # 输出 "hello world"
print(to_uppercase(str)) # 输出 "HELLO WORLD"
function toLowercase(input) {
return input.toLowerCase();
}
function toUppercase(input) {
return input.toUpperCase();
}
let str = "Hello World";
console.log(toLowercase(str)); // 输出 "hello world"
console.log(toUppercase(str)); // 输出 "HELLO WORLD"
请根据您所使用的编程语言选择适合您的情况的代码示例,并根据需要进行修改。