• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Need Help for an Array.

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey guys,
i need help to set data in Array, in this program i set values for names from 1 upto 5 , actually i want that values to be entered by using scanner class then retrieved anytime.

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you check out the Scanner API docs? It has samples of how to use the Scanner class.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Did you check out the Scanner API docs? It has samples of how to use the Scanner class.




Thanks for reply,
i not checked that docs ever but i will check,
One question i think my problem was not about scanner you know.
i have used scanner class i can get input using Scanner with any data type
my question was
how to get input from scanner to set values in Array;
then retrieve them.
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 80493
455
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using the for loop to look for the number? You don't need a number array at all. You can enter a number, calculate the index, and display the name with only one array.
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Why are you using the for loop to look for the number? You don't need a number array at all. You can enter a number, calculate the index, and display the name with only one array.



Thanks for you reply
i will try to do that.
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Muzafar Ali wrote:how to get input from scanner to set values in Array;
then retrieve them.


Use java.util.ArrayList. It's like an array, but it doesn't have a fixed size, so you can add as many Strings to it as you want
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michael Angstadt wrote:

Muzafar Ali wrote:how to get input from scanner to set values in Array;
then retrieve them.


Use java.util.ArrayList. It's like an array, but it doesn't have a fixed size, so you can add as many Strings to it as you want


Thanks fo reply,
can you post a sample for that?
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


do use "www.google.com" or any other search engines because it has many examples on array list..
 
Muzafar Ali
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jon Kho wrote:

do use "www.google.com" or any other search engines because it has many examples on array list..



Thanks for your answer,
i will try to find those by using search engine thanks for help friends.
 
reply
    Bookmark Topic Watch Topic
  • New Topic