-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwap2Number.java
More file actions
34 lines (31 loc) · 862 Bytes
/
Swap2Number.java
File metadata and controls
34 lines (31 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package questions2;
public class Swap2Number {
public static void main(String[] args) {
int a=20, b=30;
System.out.println("Before Swapping value "+ a +" " + b);
// Logic 1
// int t=a;//20
// a=b;// 30
// b=t;//20
// System.out.println("Swapping value "+ a +" " + b);
//Logic 2
// + & - operater used
// a=a+b; //50
// b=a-b; //50-30
// a=a-b; //50-20
// System.out.println("Swapping value "+ a +" " + b);
//Logic 3 * & / operateor used
// a=a*b; // 600
// b=a/b; //600/30
// a=a/b;
// System.out.println("Swapping value "+ a +" " + b);
// Logic 4 ^ Bitwish Operator
// a=a^b; //20^30=50
// b=a^b; // 50^30=20
// a=a^b; //50^20=30
// System.out.println("Swapping value "+ a +" " + b);
//Logic 5 simpal stettment
b= a+b -(a=b);
System.out.println("Swapping value "+ a +" " + b);
}
}