题解 | 交换变量值
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
//write your code here.......
Stack<Integer> stack=new Stack<>();
stack.push(a);
stack.push(b);
if(!stack.isEmpty()){
a=stack.pop();
}
if(!stack.isEmpty()){
b=stack.pop();
}
System.out.println(a+" "+b);
}
}
用了栈
查看15道真题和解析