We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 13d900d commit 935dd39Copy full SHA for 935dd39
BasicJavaProblems/SwapWithoutThirdVar.java
@@ -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