Loading...
Loading...
A weather station in the hills logs three temperature readings, which can be below zero. The report lists them from coldest to warmest. Read the three numbers and print them in ascending order, separated by single spaces.
Do it with conditions only: no arrays and no sorting methods.
Example 1
Input
12 -3 7
Output
-3 7 12
The order is -3, 7, 12.
Example 2
Input
5 5 1
Output
1 5 5
Equal numbers stay next to each other.
Try the problem first. Open one hint at a time.
You can swap two variables with a third, temporary variable.
Compare the first two and swap them if they are in the wrong order. Do the same for the last two. Now the largest is at the end.
One more compare-and-swap of the first two finishes the job.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor