Results 1 to 17 of 17
Like Tree1Likes
  • 1 Post By JosAH

Thread: Help a Freshmen.

  1. #1
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default Help a Freshmen.

    Hey,I got a problem on this question..

    Input 5 numbers and ascend them to lowest to highest using only "If,Else Statement".

    honestly,i only can get 3 inputs and can ascend them.

    so any tips how can i get the 5 inputs and ascend them to lowest to highest?? or code will be really helpful for me.

    thanks :)

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

    Default Re: Help a Freshmen.

    Quote Originally Posted by Yappie View Post
    Hey,I got a problem on this question..

    Input 5 numbers and ascend them to lowest to highest using only "If,Else Statement".

    honestly,i only can get 3 inputs and can ascend them.

    so any tips how can i get the 5 inputs and ascend them to lowest to highest?? or code will be really helpful for me.
    If you can get three numbers from the user, you can get five numbers from the user; at worst you add two more (almost identical) sequences of statements; a bit better would be to use a simple loop and an array. Give it a try and show your attempts here ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Help a Freshmen.

    Quote Originally Posted by Yappie View Post
    Help a Freshmen.
    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help a Freshmen.

    Quote Originally Posted by DarrylBurke View Post
    Please go through the Forum Rules, particularly the third paragraph.

    db
    thanks. sorry about that.

  5. #5
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default How do i Fix them to least to greatest vice versa

    i have to input 5 numbers and fix them to least to greatest them "using only if else statement"

    i have already check some codes in the internet but they can only do 3 numbers.

    How can i add 2 more numbers and to arrange them from least to greatest.

    I did try to add the 2 numbers but it fcked up the program.
    Last edited by Yappie; 07-19-2013 at 03:57 PM.

  6. #6
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: How do i Fix them to least to greatest vice versa

    show us what you have done and then people can help you.

  7. #7
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: How do i Fix them to least to greatest vice versa

    Tell us more about you program like are all the 5 elements stored in an array or not??

  8. #8
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default Re: How do i Fix them to least to greatest vice versa

    Quote Originally Posted by superhaNds View Post
    show us what you have done and then people can help you.

  9. #9
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: How do i Fix them to least to greatest vice versa

    It is tons better to save the 5 values in an array and sort it by an existing method Arrays.sort(int[] a).
    Just by seeing this it burned my eyes.

  10. #10
    harshit shah is offline Member
    Join Date
    Jan 2013
    Location
    Kolkata,India
    Posts
    86
    Rep Power
    0

    Default Re: How do i Fix them to least to greatest vice versa

    Please use arrays for better understanding and relieving complexity.

  11. #11
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default Re: How do i Fix them to least to greatest vice versa

    Quote Originally Posted by harshit shah View Post
    Please use arrays for better understanding and relieving complexity.
    i cant use array

    except if and else statement

  12. #12
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default Re: How do i Fix them to least to greatest vice versa

    Quote Originally Posted by superhaNds View Post
    It is tons better to save the 5 values in an array and sort it by an existing method Arrays.sort(int[] a).
    Just by seeing this it burned my eyes.
    cant use arrays

    only if and else.

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

    Default Re: How do i Fix them to least to greatest vice versa

    @Yappie: don't abandon this thread: Help a Freshmen. it's the same subject; I'll merger the two threads.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default Re: How do i Fix them to least to greatest vice versa

    Quote Originally Posted by JosAH View Post
    @Yappie: don't abandon this thread: Help a Freshmen. it's the same subject; I'll merger the two threads.

    kind regards,

    Jos
    noted.

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

    Default Re: Help a Freshmen.

    If you are not allowed to use arrays nor any other form of collection; you're doomed to write a lot of if-statements; if you have n variables to sort, you have to write O(n*log(n)) if-statements. If you're using a less efficient sorting methods (such as bubble sort) you have to write even more if-statements. Does your teacher/lecturer/professor want you to do that?

    kind regards,

    Jos
    Yappie likes this.
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    Yappie is offline Member
    Join Date
    Jul 2013
    Posts
    11
    Rep Power
    0

    Default Re: Help a Freshmen.

    Quote Originally Posted by JosAH View Post
    If you are not allowed to use arrays nor any other form of collection; you're doomed to write a lot of if-statements; if you have n variables to sort, you have to write O(n*log(n)) if-statements. If you're using a less efficient sorting methods (such as bubble sort) you have to write even more if-statements. Does your teacher/lecturer/professor want you to do that?

    kind regards,

    Jos
    our professor only wants us to do the if else statement, no bubble sort or something were just starting programming. any tips for me to do the easiest if else statement codes? for this exercise/question??
    Last edited by Yappie; 07-19-2013 at 04:41 PM.

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

    Default Re: Help a Freshmen.

    Quote Originally Posted by Yappie View Post
    our professor only wants us to do the if else statement, no bubble sort or something were just starting programming. any tips for me to do the easiest if else statement codes? for this exercise/question??
    But all those if-else-statements effectively are a bubble (or other) sort method for a fixed number of variables. Those if-statements have to test and swap two variables; e.g.

    Java Code:
    if (b < a) { int t= a; a= b; b= t; }
    Let's denote this statement as S(a, b) i.e. "swap a and b if b is less than a"; if you want to sort three variables a, b and c you have to execute S(a, b), S(b, c), S(a, b). You figure out what you have to do if you have to sort the five variables a, b, c, d and e.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

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