• Post Reply Bookmark Topic Watch Topic
  • New Topic

Input values to an ArrayList  RSS feed

 
Mike Arndt
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ladies and gents, I need a little help with this program. Basically I need to create something that will let the user input any number of floats(and store them into an ArrayList), and ask them to continue after each one. If they choose not to continue it should print the current contents of the arraylist. Later on I will need to be able to have them sort the list if they choose, but for now I am trying to get the input part working. Here is what I have:


I've tried a few things and well I keep getting one of two errors:


because my letsgoagain string is created inside this do while loop I assume.

OR


happens when I try and initialize the string outside the loop to counteract the previous error. As you can see, I really don't know what I'm doing and I'm sure there are simpler and more efficient ways of going about this, but I just need some insight as to why I keep getting stuck and what I can do to fix this. Any help is greatly appreciated!

Cheers,
Mike
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You can define a variable only once.
Just change it to
 
Mike Arndt
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Maneesh, that did it for me! I fixed a couple other things I noticed were wrong and now the program functions correctly. The only thing I have left is to have it sort the list in ascending or descending order depending on user input, I am trying to figure out how to user the collections.sort method and am building quite the headache hahaha. Thanks again for your help!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome!
Well done identifying and fixing the things which you found wrong. And I really like it that you intend to try and crack the sorting "headache" yourself first before asking anyone else.
For all your efforts, have a cow! Moo!
 
Mike Arndt
Greenhorn
Posts: 6
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooooh that is neat, thank you! The headache didn't last long, I figured it out and it was quite simple! Again, I appreciate the help

Best Regards,
Mike
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!