I want to be able to choose an array index using input.
Object stud1 [][] = {
{1,2,3},
{"favorite food: ","pet name: ","bday: "}
}
System.out.println("how many inputs?");
If a user inputs 1, then "favorite food:" will prompt the user and if the user inputs 2, then both "favorite food: " and "pet name: " will prompt the user and so on.
After the user completes the prompt input, this will display:
favorite food: chicken
pet: doge
birthday: december 25,1994
/////////////////////////////////////////my code/////////////////////////////////////////////
This question is similar to my other question, I just could not find the right answer for my question because I think it was confusing and not specific enough.
It's kind of working already but the problem is that when I input 1 then it still outputs everything. I only want it to output everything if the user inputs 3 which is the number of indexes in my array.
I am not pretty good with arrays yet especially multi array, I'm still experimenting.
String ctr1;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter How Many Inputs: ");
int num1 = Integer.parseInt(in.readLine());
if (num1 <= stud1.length) {
for (int x = 1; x<stud1.length;x++){
for (int i = 0; i<stud1[x].length;){
/*System.out.print("Enter Value #" + x++ +":");
ctr1 =Integer.parseInt(in.readLine());
i++;*/
System.out.println(stud1[x][i]);
ctr1 =in.readLine();
i++;
}
}