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.
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?
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.
Well, how are you deciding if you need to change the high?
I don't know. Could you help?
I mean in your code. What are you doing each time to the numbers that are input?
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
Why are you using the for loops? Just a simple if statement is all you need there.
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.
Okay I get it :)) Thanks
np Have fun!
Join our real-time social learning platform and learn together with your friends!