Java Program to Swap Two Numbers - safetxt
avatar
Java Program to Swap Two Numbers

mrt481 0.9K 28th Aug, 2022

Java 0.81 KB
Loading Please wait...
Description

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.


Recent Pastes

Please disable your adblock and script blockers to view this page