想问一下这是什么意思该怎样在代码中不出现“TO”的实现,代码希望有详尽的注释,刚刚入门的小学生
public static void main(String[] args) {
String Str = new String("Welcome to Gench ");
String Str1 = new String("to");
System.out.print("返回值 :" );
String Str2 =Str.substring(0,16);//截取
System.out.println(Str2.replace("to",Str1.toUpperCase()));//TO替换to,并打印
}
一:按空格split,把 第二个元素 转大写;
二:遍历,然后ASCL码替换 t和o;
public static void main(String[] args) {
String Str = "Welcome to Gench ";
String Str1 = "to";
System.out.println(Str.replace("to", Str1.toUpperCase()).trim());
}