问题描述
编写一个程序,输入两个整数,反别存放在变量x和y当中,然后使用自己定义的函数swap来交换这两个变量的值。
public class Main{
statuc int x,y;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
x = scanner.nextInt();
y = scanner.nextInt();
swap();
System.out.println(x+" "+y);
scanner.close();
}
private static void swap() {
int temp = x;
x = y;
y = temp;
}