位运算符

使用位运算符进行变量值互换:

 1 package text;
 2
 3 public class S1 {
 4 
 5     public static void main(String[] args){
 6         int m = 12;
 7         int n = 5;
 8         System.out.println("m:" + m + "n:" + n);
 9         m = m ^ n;
10         n = m ^ n;
11         m = m ^ n;
12         System.out.println("m:" + m + "n:" + n);
13     }
14 }

 

2 3 public class S1 { 4 5 public static void main(String[] args){ 6 int m = 12; 7 int n = 5; 8 System.out.println("m:" + m + "n:" + n
公共类S1 4 5公共静态空main(字符串args)6 int m=12;n=5;8 system . out。println(m:+m+n:+n

posted on 2018-01-15 20:38  Aoki894  阅读(116)  评论(0)    收藏  举报

导航