- public class SwapTwoNumberWithoutThirdVariable {
- public static void main(String[] args) {
- int a = 10;
- int b = 20;
- a = a + b;
- b = a - b;
- a = a - b;
- System.out.println("after swap value of a: " + a);
- System.out.println("after swap value of b: " + b);
- }
- }
Output:
after swap value of a: 20
after swap value of b: 10
No comments:
Post a Comment