| Author |
Need Help for an Array.
|
Muzafar Ali
Ranch Hand
Joined: Jun 11, 2009
Posts: 34
|
|
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.
|
~When You Learn Anything, Learn by Heart !
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8435
|
|
|
Did you check out the Scanner API docs? It has samples of how to use the Scanner class.
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Muzafar Ali
Ranch Hand
Joined: Jun 11, 2009
Posts: 34
|
|
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
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8435
|
|
|
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32654
|
|
|
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
Joined: Jun 11, 2009
Posts: 34
|
|
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.
|
 |
Michael Angstadt
Ranch Hand
Joined: Jun 17, 2009
Posts: 272
|
|
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
|
SCJP 6 || SCWCD 5
|
 |
Muzafar Ali
Ranch Hand
Joined: Jun 11, 2009
Posts: 34
|
|
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?
|
 |
Jon Kho
Ranch Hand
Joined: Jun 03, 2009
Posts: 54
|
|
do use "www.google.com" or any other search engines because it has many examples on array list..
|
 |
Muzafar Ali
Ranch Hand
Joined: Jun 11, 2009
Posts: 34
|
|
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.
|
 |
 |
|
|
subject: Need Help for an Array.
|
|
|