Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

In java, I should asked the user to enter 10 integers, then display the highest and the lowest integers he entered. How could I do that using a do while loop? Please help.

OpenStudy (e.mccormick):

How to do it is not language dependent. That would be actually coding it, but you should be able to figure that out once you have a plan. So the real question is how to make a plan. Think about this. You need two outputs, a high and a low. So, declare them! Then, what would you need to do inside the loop to detect if you need to change them?

OpenStudy (anonymous):

I know, but I can't get it. I already have my code but It can only display the right lowest number, and it displays the wrong highest number.

OpenStudy (e.mccormick):

Well, how are you deciding if you need to change the high?

OpenStudy (anonymous):

I don't know. Could you help?

OpenStudy (e.mccormick):

I mean in your code. What are you doing each time to the numbers that are input?

OpenStudy (anonymous):

Here is my code: //code to ask the user for ten integers do { value = input.nextInt(); for(int x = 1; x <= value; x++) highest = value; for(int y = 1; y >= value; y++) lowest = value; a++ } while(a <= 10) //code to display the result

OpenStudy (e.mccormick):

Why are you using the for loops? Just a simple if statement is all you need there.

OpenStudy (e.mccormick):

See, the for loops can not handle it is I enter a negative integer. If my highest is -1 and my lowest is -3, your code will miss that.

OpenStudy (anonymous):

Okay I get it :)) Thanks

OpenStudy (e.mccormick):

np Have fun!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!