# H>descending order

Printable View

• 12-24-2013, 11:44 AM
Montrose
H>descending order
I am new here in this forums and i got a question.

Q:
Create a program that gets 10 random numbers from the user and inputs it in descending order.

Example output: Input 10 numbers: 50 69 10 29 11 12 30 40 80 22
Descending order: 80 69 50 40 30 29 22 12 11 10
--------------------------------------------------------------------------------------------------

can u help me with the logic code? i was thinking using arrays for this. thanks in advance.
• 12-24-2013, 02:31 PM
Norm
Re: H>descending order
Are you working on code to sort an array of numbers?
What have you tried?
• 12-24-2013, 05:16 PM
zFollette
Re: H>descending order
What I would do it have 2 String arrays of the same fixed size (10), I would go through the input array with a loop and use the Random library to select a random index and if that index has a value in it, set the output array in order and set the current index of the input array to null.

Edit: Before Norm or gimbal2 or anyone else comes in here and disproves my method: I chose a String array because OP could enter any value in his array from -2.147 billion to +2.147 billion so there is no open number to use as a place holder (i.e -1) with a String array, null is always an open placeholder (not "null", but null)
• 12-24-2013, 05:21 PM
Norm
Re: H>descending order
Sounds like a confusion to me and way more complicated than doing a sort in a loop.
• 12-24-2013, 08:02 PM
JosAH
Re: H>descending order
Quote:

Originally Posted by zFollette
I chose a String array because OP could enter any value in his array from -2.147 billion to +2.147 billion so there is no open number to use as a place holder (i.e -1) with a String array, null is always an open placeholder (not "null", but null)

Integer objects can be null too and it would save you the conversion to/from the String type; but the method is silly to start with: simply sort the thing with a suitable Comparator.

kind regards,

Jos
• 12-24-2013, 09:10 PM
zFollette
Re: H>descending order
Quote:

Originally Posted by JosAH
Integer objects can be null too and it would save you the conversion to/from the String type; but the method is silly to start with: simply sort the thing with a suitable Comparator.

kind regards,

Jos

Fair enough.