Problem Description
将变量的引用作为函数形参,实现2个int型数据交换。
Input
输入2个int型整数。
Output
输出2个整数交换前后的值。
Sample Input
88 66
Sample Output
88 66
66 88
AC代码:
import java.util.Scanner;
class A {
int x, y;
public A(int x, int y) {
super();
this.x = x;
this.y = y;
}
public A Swap(int n, int m) {
x = m;
y = n;
return new A(x, y);
}
}
public class Main {
public static void main(String[] args) {
Scanner mi = new Scanner(System.in);
A a = new A(mi.nextInt(), mi.nextInt());
System.out.println(a.x + " " + a.y);
a.Swap(a.x, a.y);
System.out.println(a.x + " " + a.y);
mi.close();
}
}
————
余生还请多多指教!