small case change m and n
class Test{ public static void main(String[] args){ int m=12; int n=5; System.out.println("m:"+m+",n:"+n); //方法1: 提供临时变量 int temp = m; m=n; n=temp; System.out.println("m:"+m+",n:"+n); //方法2: 当m和n比较大时,有可能出现精度损失 m=m+n; n=m-n; m=m-n; System.out.println("m:"+m+",n:"+n); //方法3: 抑或位运算符 m=m^n; n=m^n; //(m^n)^n==m m=m^n; //(m^n)^m==n } }
不积小流,无以成江河!记住一万个小时定律!