美文网首页
不通过中间变量交换A B两数的值(Java)

不通过中间变量交换A B两数的值(Java)

作者: Jiafu | 来源:发表于2017-09-29 15:19 被阅读0次
// 交换a、b的值,不通过中间变量
public class SwapAB {
    public static void main(String[] args){
        int a = 8, b =5;
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        System.out.println("a is:" + a);
        System.out.println("b is:" + b);
    }
}

相关文章

网友评论

      本文标题:不通过中间变量交换A B两数的值(Java)

      本文链接:https://www.haomeiwen.com/subject/xcmiextx.html