In: Computer Science
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2. It will generate ten multiplication problems ranging from 2x1 to 2x10. For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently.
After testing a total of 10 multiplication problems, your program should ask whether the user would like to try another starting number. If the user answers "yes", your program should generate another corresponding ten multiplication problems. This procedure should repeat until the user indicated "no".
SOURCE CODE: *Please follow the comments to better understand the code. **Please look at the Screenshot below and use this code to copy-paste. ***The code in the below screenshot is neatly indented for better understanding. import java.util.Scanner; public class MultiplicationProblems { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); while (true) { // take user input System.out.print("Enter the starting number: "); int num = scanner.nextInt(); // generate numbers and store them in an array int[] problems=new int[10]; for(int i=1;i<=10;i++) problems[i-1]=num*i; // ask the user for correct answers for problems System.out.println("Please enter the correct answers for the following: "); int value=1; while(value<=10) { System.out.print("What is "+num+" * "+value+" ? : "); int ans=scanner.nextInt(); if(ans==problems[value-1]) value++; else System.out.println("Wrong! Enter again."); } // ask user if continue or not System.out.println("Do you like to try with another number? "); String choice=scanner.next(); if(choice.equals("no")) break; } System.out.println("Good Bye !!"); } }
===========
SCREENSHOT:
outputs