Problem

(Addition quiz) Rewrite Listing 1 RepeatAdditionQuiz.java to alert the user if an answer i...

(Addition quiz) Rewrite Listing 1 RepeatAdditionQuiz.java to alert the user if an answer is entered again. Hint: use an array list to store answers. Here is a sample run:

LISTING 1 RepeatAdditionQuiz.java

1 import java.util.Scanner;

2

3 public class RepeatAdditionQuiz {

4 public static void main(String[] args) {

5 int number1 = (int)(Math.random() * 10);

6 int number2 = (int)(Math.random() * 10);

7

8 // Create a Scanner

9 Scanner input = new Scanner(System.in);

10

11 System.out.print(

12 "What is " + number1 + " + " + number2 + "? ");

13 int answer = input.nextInt();

14

15 while (number1 + number2 != answer) {

16 System.out.print("Wrong answer. Try again. What is "

17 + number1 + " + " + number2 + "? ");

18 answer = input.nextInt();

19 }

20

21 System.out.println("You got it!");

22 }

23 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT