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:
Code:
import
javax.swing.JOptionPane;
public
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]+"";
}
JOptionPane.showMessageDialog(null, output, "Arrays", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}//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