package rew;
import java.util.Scanner;
public class VariableExchange {
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
System.out.println("请输入A的值");
long A=scan.nextLong();
System.out.println("请输入B的值");
long B=scan.nextLong();
System.out.println("A="+A+"\tB="+B);
System.out.println("执行变量互换...");
A=A^B;
B=A^B;
A=A^B;
System.out.println("A="+A+"\tB="+B);
}
import java.util.Scanner;
public class VariableExchange {
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
System.out.println("请输入A的值");
long A=scan.nextLong();
System.out.println("请输入B的值");
long B=scan.nextLong();
System.out.println("A="+A+"\tB="+B);
System.out.println("执行变量互换...");
A=A^B;
B=A^B;
A=A^B;
System.out.println("A="+A+"\tB="+B);
}
}
结果:
A B例子说明:
A 0110
B 1010
A=A^B后
A 1100
B=A^B后
B 0110
A=A^B后
A 1010