-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwapping_number.java
More file actions
34 lines (28 loc) · 851 Bytes
/
Swapping_number.java
File metadata and controls
34 lines (28 loc) · 851 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 Exp2;
import java.util.Scanner;
public class Swapping_number {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter Interger value of variable a :");
int a=sc.nextInt();
System.out.println("Enter Interger value of variable b:");
int b=sc.nextInt();
System.out.println("Before swapping value of a variable: "+a+" \nBefore swapping value of b variable: "+b);
/* 1st technique for Swapping values of two variables
int temp;
temp=a;
a=b;
b=temp
*/
/* 2nd technique for swapping values of two variables
b=a^b;
a=a^b;
b=a^b;
*/
// 3rd technique for swapping values of two variables
a = a + b;
b = a - b;
a = a - b;
System.out.println("After swapping value of a variable: "+a+"\nAfter swapping value of b variable: "+b);
}
}