-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathProgram1
More file actions
24 lines (17 loc) · 726 Bytes
/
Program1
File metadata and controls
24 lines (17 loc) · 726 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
public class SwapNumbers {
public static void main(String[] args) {
float first = 1.20f, second = 2.45f;
System.out.println("--Before swap--");
System.out.print("First number = " + first)
System.out.println("Second number = " + second);
// Value of first is assigned to temporary
float 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);
}
}