Purpose of this program: Create a multiplication flashcard generator for a young relative, and have it repeat 10 times.
//Importing Random Class
import java.util.Random;
import java.util.Scanner;
public class Rand
{
public static void main(String[] args)
{
flashcards();
flashcards();
flashcards();
flashcards();
flashcards();
flashcards();
flashcards();
flashcards();
flashcards();
flashcards();
}
public static void flashcards()
{
// Inputs
Scanner in = new Scanner(System.in);
Random rand = new Random();
int randomNumber = rand.nextInt(11);
int randomNumber2 = rand.nextInt(11);
// Outputs
System.out.print("What is " + (randomNumber) + " x " + (randomNumber2)
+ "? ");
// Inputs
int answer = in.nextInt();
String answerString = "";
answerString = Integer.toString(answer);
System.out.println("Your answer: " + answer);
System.out.println("Correct answer: "
+ String.valueOf(randomNumber * randomNumber2));
String randomEquation = String.valueOf(randomNumber * randomNumber2);
// Outputs
if (answerString.equals(randomEquation))
{
System.out.println("Correct!");
}
if (!answerString.equals(randomEquation))
{
System.out.println("Incorrect.");
}
}
}