Results 1 to 6 of 6
  1. #1
    Montrose is offline Member
    Join Date
    Dec 2013
    Posts
    1
    Rep Power
    0

    Post 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.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: H>descending order

    Are you working on code to sort an array of numbers?
    What have you tried?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default 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)
    Last edited by zFollette; 12-24-2013 at 05:19 PM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default Re: H>descending order

    Sounds like a confusion to me and way more complicated than doing a sort in a loop.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default Re: H>descending order

    Quote Originally Posted by zFollette View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    zFollette is offline ▼ dafuq did I do?
    Join Date
    Dec 2013
    Posts
    203
    Rep Power
    0

    Default Re: H>descending order

    Quote Originally Posted by JosAH View Post
    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.

Similar Threads

  1. Insertion Sort Algorithm in Descending Order
    By Notthead in forum Advanced Java
    Replies: 12
    Last Post: 12-07-2011, 09:27 PM
  2. Sorting in ascending and descending order
    By flpanthers1 in forum New To Java
    Replies: 10
    Last Post: 06-27-2011, 04:48 PM
  3. Sorting in descending order
    By santanu in forum New To Java
    Replies: 6
    Last Post: 11-27-2008, 12:43 AM
  4. Descending order
    By santanu in forum New To Java
    Replies: 1
    Last Post: 11-04-2008, 05:33 PM
  5. Display the data in Descending order
    By santanu in forum New To Java
    Replies: 2
    Last Post: 10-31-2008, 01:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •