Java : Program swapping two numbers without using third variable


public class SwapTwoNo {

/**
* @param args
*/
public static void swap(int a , int b){

a = b+a;
b = a-b;
a = a-b;

System.out.println("Values of a and b after swap := " + a +" "+ b + " respectively");
}


public static void main(String[] args) {

int a = 5;
int b = 6;
System.out.println("Values of a and b before swap := " + a +" "+ b + " respectively");
swap(a,b);

}
}

No comments:

Post a Comment

πŸ””Announcement : Visit the new website/blog πŸ””

πŸ””πŸ””πŸ”” Announcement :  Visit the new website/blog πŸ””πŸ””πŸ”” Dear readers, Thank you for reading my blog. If you could have used the little info...