Skip to content

Commit 935dd39

Browse files
completed
1 parent 13d900d commit 935dd39

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package BasicJavaProblems;
2+
3+
public class SwapWithoutThirdVar {
4+
5+
6+
static void swapByadd(int a,int b){
7+
System.out.println("SwapByAddandSub");
8+
System.out.println("Before Swap :"+a+" "+b);
9+
b=a+b; //sum of two numbers b=10+20 ==>b=30
10+
a=b-a; //a=30-10 ==>a=20
11+
b=b-a; //b=30-20 ==>b=10
12+
System.out.println("After Swap :"+a+" "+b);
13+
}
14+
public static void main(String[] args) {
15+
swapByadd(10,20);
16+
17+
}
18+
}

0 commit comments

Comments
 (0)