I have to make an applet that gives you 2 single digit integers and you have to multiply and then it will tell you if you are correct. I got it to work but how do I make it continue the same set of numbers until you provide the correct answer. As I have it now it moves on to a new set of numbers whether you get it right or not. This is what I have so far.:

import java.awt.*;
import java.util.Random;
import java.util.Scanner;
import javax.swing.*;

public class Assignment6 extends JApplet{

    private Random randomNumbers = new Random(); 
    private enum Status { Right, Wrong };

    public void init(){


     while (true)
     {        
        int number1 = 1 + randomNumbers.nextInt( 10 ); // first die roll
        int number2 = 1 + randomNumbers.nextInt( 10 ); // second die roll
        int multiplication = number1 * number2;
        int mOfNumbers;
        Status answerStatus;


          String input = JOptionPane.showInputDialog( 
           "How much is " + number1 + " times " + number2 + "? " );

                 mOfNumbers = Integer.parseInt(input);

          // determine answer status
             if ( mOfNumbers == multiplication ) // win by making point
                answerStatus = Status.Right;
             else
                answerStatus = Status.Wrong;



             if ( answerStatus == Status.Right )
             {
                JOptionPane.showMessageDialog(null, "Very Good! " );
                break;
             }
             else
                JOptionPane.showMessageDialog(null, "No. Please try again." );

     } // end while

   } // end init

}
 int number1 = 1 + randomNumbers.nextInt( 10 ); // first die roll
         int number2 = 1 + randomNumbers.nextInt( 10 ); // second die roll

that will generate the new numbers. add a condition which must be met for these lines to be ran, and put the first declaration of these values outside your while loop, to enlarge their scope.

This article has been dead for over six months. Start a new discussion instead.