1# Swap without using any temp variable
2x = 66
3y = 77
4
5print("Original: ", x,y)
6
7x = x - y
8y = x + y
9x = y - x
10
11print("Swapped 1st time: ", x,y)
12
13x = x + y
14y = x - y
15x = x - y
16
17print("Swapped 2nd time: ", x,y)
18
19# Output:
20# Original: 66 77
21# Swapped 1st time: 77 66
22# Swapped 2nd time: 66 77
1import java.*;
2
3class noTemp {
4
5 public static void main(String a[])
6 {
7 int x = 10;
8 int y = 5;
9 x = x + y;
10 y = x - y;
11 x = x - y;
12 System.out.println(x , y);
13 }
14}