public class main {
public static void main(string[] args) {
int num1 = 11;
int num2 = 22;
system.out.println("before the call: num1 is " + num1 + " and num2 is " + num2);
swap(num1, num2);
system.out.println("after the call: num1 is " + num1 + " and num2 is " + num2);
}
public static void swap(int num1, int num2) {
system.out.println("num1 is " + num1 + " and num2 is " + num2 + " in method of swap.(before)");
int tmp = num1;
num1 = num2;
num2 = tmp;
system.out.println("num1 is " + num1 + " and num2 is " + num2 + " in method of swap.(after)");
}
}
运行结果如下
before the call: num1 is 11 and num2 is 22
num1 is 11 and num2 is 22 in method of swap.(before)
num1 is 22 and num2 is 11 in method of swap.(after)
after the call: num1 is 11 and num2 is 22