Skip to content
Advertisement

How to end while loop for integer gathering array in java?

I am wring a program that askes the user to give any value they want as long as it is a whole number, and that value will be placed in a array. They can do this asmany times as they would like, until they add -1 to the array. I am having a hard time figurig out how to get the loop to end. My code:

JavaScript

I think the issue is in my if conditional. Not sure what the correct way to write out the logic would be.

Advertisement

Answer

Just change:

JavaScript

To:

JavaScript

If you only want POSITIVE ints to be added, then also change your if statement to:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement