• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Loop with scanner

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What I am trying to do here is to make an array with the size asked from the user. Then fill the array with the numbers from scanner. However I am stuck, because the code just asks once, and not as many times as the array's size.

I probably should do it with something else and not an if loop, but I can't figure it out.
 
Bartender
Posts: 242
27
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The issue here is that you have a semicolon after your looping statement, which means the For loop has an empty body. So the for loop does nothing, and then executes your following code one time. To resolve, remove the extra semicolon.
 
Aron Gaspar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zachary Griggs wrote:The issue here is that you have a semicolon after your looping statement, which means the For loop has an empty body. So the for loop does nothing, and then executes your following code one time. To resolve, remove the extra semicolon.


oh that was a bit awkward.
thank you so much!
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aron Gaspar wrote:What I am trying to do here is to make an array . . .

[pedantic mode]No you aren't; you are populating a List. When it says ArrayList, it doesn't mean you are creating an array; it means the List maintains an array with all its elements in.[/pedantic mode]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic