Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Loop help?

I am trying to do an assignment outside of treehouse, and what i need to do is have a scanner and a loop that will accept multiple numerical inputs. (Example: 1 3 5 9 6...) I am just confused on how i can store essentially an unlimited number of inputs into a variable. Ill have to also create methods to find the smallest and largest inputs, the number of even and odd inputs, the cumulative totals, and the adjacent duplicates. So would i have to also do loops in each method, or is there a way that i could have just one loop for the inputs and then have those inputs carry down into the methods? Thank you to anyone who can help me out here or shed some light for this noobie programmer.

1 Answer

Hey Thomas,

this is i cool task !

I would ask the user how many numerical inputs he/she wants to input. Then I would cast this String-number (Scanner input is always a String) to an Integer. Then I would use a loop, that takes the inputs and stores the results into an array. The number of loops will be the integer we get from the user.

After this we could analize the array. We create a for-loop or for-each loop that goes over every member of the arrya and stores max and mins into a variable ...

Let me know if this is a bit helpful ... or you need assistance

Grigorij