这是一道很无语的题。。。。这个swap 函数压根用不到,因为java是值传递,经过swap函数操作之后的 x 和 y 并没有变化。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
swap(x, y);
System.out.println(y + " " + x);
sc.close();
}
public static void swap(int x, int y) {
int tmp = x;
x = y;
y = tmp;
}
}
正如下面的提交了一次仍然是100分,一个空的swap函数。。。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
System.out.println(y + " " + x);
sc.close();
}
public static void swap(int x, int y) {
}
}