-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwapTwoNumbers.java
More file actions
50 lines (34 loc) · 1.18 KB
/
SwapTwoNumbers.java
File metadata and controls
50 lines (34 loc) · 1.18 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
public class SwapTwoNumbers {
public static void main(String[] args) {
// -----------------------Method 1------------------------
Scanner scanner=new Scanner(System.in);
System.out.println("----------Before Swapping--------------");
System.out.print("Enter First Number: ");
double num1=scanner.nextDouble();
System.out.print("Enter Second Number: ");
double num2=scanner.nextDouble();
scanner.close();
double temp;
temp=num1;
num1=num2;
num2=temp;
System.out.println("----------After Swapping--------------");
System.out.println("First Number = "+num1);
System.out.println("Second Number = "+num2);
/* Scanner scanner=new Scanner(System.in);
System.out.println("----------Before Swapping--------------");
System.out.print("Enter First Number: ");
double num1=scanner.nextDouble();
System.out.print("Enter Second Number: ");
double num2=scanner.nextDouble();
scanner.close();
num1=num1-num2;
num2=num1+num2;
num1=num2-num1;
System.out.println("----------After Swapping--------------");
System.out.println("First Number = "+num1);
System.out.println("Second Number = "+num2);
*/
}
}