1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// with third variable class SwapTwoNum{ public static void main(String args[]){ int x = 34; int y = 50; int temp = x; x = y; y = temp; System.out.printf("X is : %d, Y is : %d",x,y); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Without Third Variable class SwapTwoNumWithout{ public static void main(String args[]){ int x = 34; int y = 50; x = x+y; y = x-y; x = x-y; System.out.printf("X is : %d, Y is : %d",x,y); } } |