标签:rgs static 变量 ati int 交换 world public hello
在 Java 中不使用多余变量交换两个字符串
public class Test {
public static void main(String[] args) {
String a = "Hello";
String b = "World";
System.out.println("Strings before swap: a = " + a + " and b = " + b);
a = a + b;
b = a.substring(0, a.length() - b.length());
a = a.substring(b.length());
System.out.println("Strings after swap: a = " + a + " and b = " + b);
}
}
Strings before swap: a = Hello and b = World
Strings after swap: a = World and b = Hello
标签:rgs static 变量 ati int 交换 world public hello
原文地址:https://www.cnblogs.com/hglibin/p/11291666.html