I have a program that will help the user to learn a multiplication table and then show results of right/wrong answers. The first step is to simply ask the user for which multiplication table it want to work on (1-9). And then the user will get a random sequence of number multiplied by the chosen multiplication table. If the user answers correctly then that number won't be shown again, but if incorrectly then it will be shown until the correct answer is made.
One scenario could be that the user chooses "3", and it will then be displayed in a random sequence such as (3x7 =, 3x1 =, 3x9 =...). And the user will answer after each "=". Right now, I can only print it all in ascending order, should I use Random multiplied with the chosen table in a while loop instead?.
My second issue, is how I can ask the incorrectly answered numbers again, until correctly answered? Am I right to think that a for loop isn't the best choice in this case?
Here is my code so far:
public class Multiplication {
public static void main (String[] args) {
Scanner inread = new Scanner (System.in);
int answer;
System.out.println("Choose multiplication table (1-9)");
int num1= inread.nextInt();
for (int i=1; i<11; i++) {
System.out.println("Write answer after = ");
System.out.println(num1 + " x " + (i) + " = ");
answer=inread.nextInt();
if (answer == (num1 * i) ) {
System.out.println("Correct answer");
// Do not show that number again
}
else {
System.err.println("Wrong answer");
//Show this number again.
}
}
}
}
New code after int num1 = inread.nextInt();
unanswered.add(1);
unanswered.add(2);
unanswered.add(3);
unanswered.add(4);
unanswered.add(5);
unanswered.add(6);
unanswered.add(7);
unanswered.add(8);
unanswered.add(9);
unanswered.add(10);
Collections.shuffle(unanswered);
while (!unanswered.isEmpty()) {
System.out.println(num1 + "*" + "unanswered" + " = "); //?
answer = inread.nextInt();
if (answer == (num1 * unanswered)) { //?
unanswered.remove(unanswered); //?
}
}
So, I think this is almost the way you suggested? However I'm sure I could add the numbers in a more beautiful way. I am used to looping through lists with a for loop in order to then use the counter to display the list. So where I putted a "?" is because I am not sure how to specify where in the list I am trying, for example to remove a number.
Or should I have the while loop, inside the for loop that I originally had? So that I could use the (i) in the for loop to specify where in the list I will display and perhaps remove?