两数互换的例子

public class Nums{

public static void main(String[] args){

    java.util.Scanner input = new java.util.Scanner(System.in);
    System.out.println("请输入第一个数字:");
    int num1 = input.nextInt();

    System.out.println("请输入第二个数字:");
    int num2 = input.nextInt();

    int temp;
    temp = num1;
    num1 = num2;
    num2 = temp;

    System.out.println("num1:"+num1);
    System.out.println("num2:"+num2);
}

}

你可能感兴趣的:(两数互换的例子)