Sorting three numbers

  • 8
Planet Linear Chaos is populated by isomorphs. They are believed to have invented sorting algorithms. Everything in their heads is extremely well-ordered. They only issue planetary visas to people who know at least 7 sorting algorithms. Let's take our first step toward Linear Chaos: read three numbers from the keyboard, put them in descending order, and then display them on the screen.
You can't complete this task, because you're not signed in.
Comments (32)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Sinisa Level 7, Banja Luka, Bosnia and Herzegovina
16 February, 13:23
From user input create an Integer (not int bcs it can't be reverse sorted later) array, Arrays.sort it with reverse order (import Arrays and Collections), use for loop to print the previously sorted elements, done. Wasting time with multiple IF conditions.
Davidh Dionicio Level 14, Lima, Peru
18 January, 21:52
if (max(a,b)<max(b,c))
            System.out.println(max(b,c)+" "+max(min(b,c),a)+" "+min(min(a,b),c));
            System.out.println(max(a,b)+" "+max(min(a,b),c)+" "+min(min(a,b),c));
I did it like this, tell me if this was done?
CKB Level 6, Oslo, Norway
7 November 2020, 16:07
I simply used the Collections framework's .sort() and .reverse() methods. Is that considered cheating?
Chandan Thapa Level 22, Dubai, United Arab Emirates
3 October 2020, 07:31
Found to be hardest so far!! Did not use for loop but just tried with if else statements and took my 6 attempts to pass the test.. phew!! Good one!
Joe M Level 9, East Coast, United States
27 September 2020, 20:51
I like Dyrits' answer. Mine was messier. But..I used buffered reader, Math. max, Math.min and abunch of if/elses
Dyrits Level 22, Die, France
3 July 2020, 07:37
Can't we simply use Math.min() and Math.max() and deduce them from the sum for the middle value ?
Switch/Cypher Level 25, Bexleyheath, United Kingdom
7 September 2020, 15:20
Exactly what i did ..... eventually!
Edddieg Level 15, Providence, United States
10 June 2020, 05:31
I don't like to brag ... but I got this on the first try doing something good ... tbh I feel like its best to work on a regular IDE before transferring your code here
Andrei Level 20
20 September 2020, 13:13
you just did that! why would you do something you don't like? lol...
Prassha Level 24, Chagford, United Kingdom
29 April 2020, 14:53
Can any one advise me, what is wrong with the code. I am seeing this message: If you enter the numbers 2, 1, 2, then the program should display: 2 2 1
Prassha Level 24, Chagford, United Kingdom
29 April 2020, 15:28
Hi, i figure it out. Mistake was my code was printing the answer twice. Thank you.
4 April 2020, 12:45
Tip for everyone here. Your code will fail i you display ANYTHING other than the numbers in descending order. I made the mistake o displaying the unsorted numbers first. ONLY display the SORTED list.
shubham sharma Level 5, Delhi, India
1 February 2020, 06:11
what's wrong