//1.加减运算交换 double num1 = 0.01; double num2 = 9.99; //进行加减运算,利用赋值交换 num1 = num1 + num2; num2 = num1 - num2; num1 = num1 - num2; System.out.println(num1);//输出 9.99 System.out.println(num2);//输出 0.009999999999999787
//2.异或运算交换(只能用于整数) int num1 = 10; int num2 = 90; //进行加减运算,利用赋值交换 num1 = num1 ^ num2; num2 = num1 ^ num2; num1 = num1 ^ num2; System.out.println(num1);//输出 90 System.out.println(num2);//输出 10
//3.引用中间变量交换 double num1 = 0.01; double num2 = 9.99; //引用中间变量 temp,利用赋值进行交换 double temp = num1; num1 = num2; num2 = temp; System.out.println(num1);//输出 9.99 System.out.println(num2);//输出 0.01
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)