Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Storing User Names in Array (http://www.go4expert.com/forums/storing-user-names-array-t15509/)

javaFunk 15Dec2008 22:56

Storing User Names in Array
I am trying to do this:

"Please enter your name"
This then gets stored in array at position [0]

"How many 6 number lines do you want?"
"Please choose 6 numbers"

These 6 numbers get stored in a 2D array [6][20]

Once this is done I then want to give the option to enter a new user name and this user can enter more lines of 6 numbers...
At the moment the only way I can populate the array is to user a for loop but this keeps asking for the user name instead of then asking for their numbers:



class returnArray {

publicstaticvoid main(String[] args) {
String output;
String [] usersData;

//get usersData

usersData = readUsersData();

//print array

output =
"UsersNames: ";
for(int loop = 0; loop <usersData.length; loop++){
output = output +usersData[loop]+
null, output, "Arrays", JOptionPane.INFORMATION_MESSAGE);

//end main

//user defined method

publicstatic String [] readUsersData(){
String nameString;
finalint ARRAY_SIZE = 5;
String [] tempArray =
new String[ARRAY_SIZE];
for (int loop = 0; loop<tempArray.length; loop++){
//read in num1 and convert to integer

nameString = JOptionPane.showInputDialog(
"Enter your name");
tempArray[loop] = nameString;


return tempArray;
//end this method

//end class

All times are GMT +5.5. The time now is 06:03.