-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAeSwap.java
More file actions
29 lines (21 loc) · 852 Bytes
/
Copy pathAeSwap.java
File metadata and controls
29 lines (21 loc) · 852 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
package bas1;
import java.util.Scanner;
public class AeSwap {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.println("Enter two numbers");
// nextInt() reads the next integer from the keyboard
int first = reader.nextInt();
int second = reader.nextInt();
System.out.println("--Before swap--"); // Value of first is assigned to temporary
int temporary = first;
// Value of second is assigned to first
first = second;
// Value of temporary (which contains the initial value of first) is assigned to second
second = temporary;
System.out.println("--After swap--");
System.out.println("First number = " + first);
System.out.println("Second number = " + second);
reader.close();
}
}