I am trying to write a Java Program that teaches multiplication by displaying a multiplication problem (i.e. How much is 6 times 7 with 6 and 7 being the random number). Then the person is supposed to guess/answer the problem. If they get it right then a message is displayed "Very Good" and ask another question and if wrong "No. Please try again." and repeat the question. I have managed with some assistance to figure out how to get most of the program but I cannot figure out how to loop the whole thing so that it continues to ask more questions after the user gets the answer correct. Help is appreciated
import java.util.Random;
import java.util.Scanner;
public class Multiplication1
{
public static void main (String args [] )
{
Scanner input = new Scanner( System.in );
Random generator = new Random(); // random number generator
int x = (int)(Math.random()*12);
int y = (int)(Math.random()*12);
int z = x*y;
int studentAnswer;
System.out.print("\nHow much is " +x+ " times " +y+ "?" );
studentAnswer = input.nextInt();
if ( studentAnswer == z )
System.out.println( "\nVery Good!\n" );
while (studentAnswer != z )
{
System.out.println( "\nNo. Please try again.\n" );
System.out.print("\nHow much is " +x+ " times " +y+ "?" );
studentAnswer = input.nextInt();
} // end inner while
}
}
2007-03-01
05:59:04
·
1 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design