20 October 2016

Swap Two Numbers



public class SwapTwoNumbers {

    public static void main(String[] args) {

        int x = 5, y = 10;

        x = x ^ y ^ (y = x);

        System.out.println("x = " + x);
        System.out.println("y = " + y);

    }

}

No comments :

My Blog List

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.