具体细节见:https://blog.csdn.net/wwt18811707971/article/details/78291490
package 实现两个变量的互换; import java.util.Scanner; public class 实现两个变量的互换 { 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+"\t B ="+B); System.out.println("执行变量互换"); A = A^B; B = B^A; A = A^B; System.out.println("A ="+A+"\t B ="+B); } }