-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswap_twonumbers.java
More file actions
35 lines (31 loc) · 837 Bytes
/
swap_twonumbers.java
File metadata and controls
35 lines (31 loc) · 837 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
35
//With temporary variable
//public class swap_twonumbers {
// public static void swapi(int x,int y){
// int temp =x;
// x=y;
// y=temp;
// System.out.println("Number After swapping: x is : "+x+" y is : "+y);
// }
//
// public static void main(String[] args) {
// int x=10;
// int y=20;
// System.out.println("Number After swapping: x is : "+x+" y is : "+y);
// swapi(x,y);
// }
//}
//Without temporary variable
public class swap_twonumbers {
public static void swap1(int m,int n){
m=m+n;
n=m-n;
m=m-n;
System.out.println("After Swap: m = "+m+" n = "+n);
}
public static void main(String[] args) {
int m=23;
int n=54;
System.out.println("Before Swap: m = "+m+" n = "+n);
swap1(m,n);
}
}