Java Program to Swap Two Numbers
mrt481 899 28th Aug, 2022
Loading Please wait...
In the above program, two numbers 1.20f and 2.45f which are to be swapped are stored in variables: first and second respectively. The variables are printed before swapping using println() to see the results clearly after swapping is done. First, the value of first is stored in variable temporary (temporary = 1.20f). Then, value of second is stored in first (first = 2.45f). And, finally value of temporary is stored in second (second = 1.20f). This completes the swapping process and the variables are printed on the screen. Remember, the only use of temporary is to hold the value of first before swapping. You can also swap the numbers without using temporary.
- C++ Program to Add Two Numbers
C++ | 5.4K | 10 months ago
- C++ Program to Print Number Entered by User
C++ | 3.2K | 10 months ago
- C++ "Hello, World!" Program
C++ | 2.3K | 10 months ago