Swaping Two Numbers Using Two Variable

swaping of two numbers using only TWO Variables
SOURCE : SwapUsingTwoVariable.java



public class SwapUsingTwoVariable {

/**
* @param args
*/
public static void main(String[] args) {


SwapUsingTwoVariable swap = new SwapUsingTwoVariable();
swap.numberswap(25,32);

swap.numberp(34,76);

}

private void numberp(int i, int j) {

System.out.println("number before swap " + i+ " "+j);
i=i^j;
j=i^j;
i=i^j;


System.out.println("number after swap " + i+ " "+j ) ;

}

private void numberswap(int num1,int num2){

System.out.println("number before swap " + num1+ " "+num2);
num1=num1+num2;
num2=num1-num2;
num1=num1-num2;


System.out.println("number after swap " + num1+ " "+num2 ) ;


}

}




INPUT

number before swap 25 32
number before swap 34 76




OUTPUT



number after swap 32 25
number after swap 76 34







Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment