# Help a Freshmen.

• 07-17-2013, 04:18 PM
Yappie
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 :)
• 07-17-2013, 04:32 PM
JosAH
Re: Help a Freshmen.
Quote:

Originally Posted by Yappie
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
• 07-17-2013, 04:48 PM
DarrylBurke
Re: Help a Freshmen.
Quote:

Originally Posted by Yappie
Help a Freshmen.

Please go through the Forum Rules, particularly the third paragraph.

db
• 07-17-2013, 04:54 PM
Yappie
Re: Help a Freshmen.
Quote:

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

db

• 07-19-2013, 02:41 PM
Yappie
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.
• 07-19-2013, 02:57 PM
superhaNds
Re: How do i Fix them to least to greatest vice versa
show us what you have done and then people can help you.
• 07-19-2013, 02:58 PM
harshit shah
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??
• 07-19-2013, 03:19 PM
Yappie
Re: How do i Fix them to least to greatest vice versa
Quote:

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

http://i.imgur.com/qQsGI5j.png
• 07-19-2013, 03:25 PM
superhaNds
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.
• 07-19-2013, 03:27 PM
harshit shah
Re: How do i Fix them to least to greatest vice versa
Please use arrays for better understanding and relieving complexity.
• 07-19-2013, 03:44 PM
Yappie
Re: How do i Fix them to least to greatest vice versa
Quote:

Originally Posted by harshit shah
Please use arrays for better understanding and relieving complexity.

i cant use array

except if and else statement
• 07-19-2013, 03:45 PM
Yappie
Re: How do i Fix them to least to greatest vice versa
Quote:

Originally Posted by superhaNds
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.
• 07-19-2013, 03:59 PM
JosAH
Re: How do i Fix them to least to greatest vice versa
@Yappie: don't abandon this thread: http://www.java-forums.org/new-java/...ml#post347156; it's the same subject; I'll merger the two threads.

kind regards,

Jos
• 07-19-2013, 03:59 PM
Yappie
Re: How do i Fix them to least to greatest vice versa
Quote:

Originally Posted by JosAH
@Yappie: don't abandon this thread: http://www.java-forums.org/new-java/...ml#post347156; it's the same subject; I'll merger the two threads.

kind regards,

Jos

noted.
• 07-19-2013, 04:17 PM
JosAH
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
• 07-19-2013, 04:38 PM
Yappie
Re: Help a Freshmen.
Quote:

Originally Posted by JosAH
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??
• 07-19-2013, 05:17 PM
JosAH
Re: Help a Freshmen.
Quote:

Originally Posted by Yappie
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.

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