Java—交换两个整数的值(顺序结构)
Description
交换两个变量的值,由终端输入两个整数给变量x、y,然后交换x和y的值后,输出x和y。
Input
从键盘输入两个整数变量x和y;
Output
在交换x、y的值后将x和y输出!
Sample
Input
4 6
Output
6 4
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner reader = new Scanner(System.in);
int a, b, temp;
a = reader.nextInt();
b = reader.nextInt();
temp = a;
a = b;
b = temp;
System.out.print(a + " " + b);
reader.close();
}
}