3. Write a program that deliberately contains an endless or infinite while loop. The loop should generate multiplication questions with single digit random integers. Users can answer the questions and get immediate feedback. After each question, the user should be able to stop the questions and get an overall result. See Example Output.Example OutputWhat is 7 * 6 ? 42Correct. Nice work!Want more questions y or n ? yWhat is 8 * 5 ? 40Correct. Nice work!Want more questions y or n ? yWhat is 5 * 5 ? 25Correct. Nice work!Want more questions y or n ? yWhat is 8 * 9 ? 66Incorrect. The product is 72Want more questions y or n ? nYou scored 3 out of 4 Required Textbook: Introduction to Java Programming and Data Structures, Comprehensive Version, Edition: 11thAuthor: Y. Daniel LiangPublisher: PearsonISBN: 9780134670942

Question
Asked Oct 29, 2019
75 views

3. Write a program that deliberately contains an endless or infinite while loop. The loop should generate multiplication questions with single digit random integers. Users can answer the questions and get immediate feedback. After each question, the user should be able to stop the questions and get an overall result. See Example Output.

Example Output

What is 7 * 6 ? 42
Correct. Nice work!
Want more questions y or n ? y
What is 8 * 5 ? 40
Correct. Nice work!
Want more questions y or n ? y
What is 5 * 5 ? 25
Correct. Nice work!
Want more questions y or n ? y
What is 8 * 9 ? 66
Incorrect. The product is 72
Want more questions y or n ? n
You scored 3 out of 4
 

Required Textbook: Introduction to Java Programming and Data Structures, Comprehensive Version, Edition: 11th

Author: Y. Daniel Liang

Publisher: Pearson

ISBN: 9780134670942

check_circle

Expert Answer

star
star
star
star
star
1 Rating
Step 1

Following is the java program:
variables used:
z is used to store the result of the multiplication of two single-digit integers.
c is used to store number of correct answers.
t stores the total number of questions.
random() method is used to generate single-digit random numbers. A do-while loop is used to continue the program asking multiplication questions until users press N or n.

Step 2

Code:
import java.io.*;
import java.util.*;

public class Main {

private static char choice;

public static void main(String[] args) {
Scanner s=new Scanner(System.in); //for reading input from user
int z,c=0,t=0; //declaring variables
do
{
t++; //count total questions
int x = (int) (Math.random() * 10);//generating single digit random number
int y = (int) (Math.random() * 10);//generating single digit random number

System.out.println("What is "+x+" * "+y+" ? ");
z=s.nextInt(); //read value of z
if(x*y==z) //condition to check if answer is correct ...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: How to use if else statement

A: If-else statement is used when a particular block of code is to be executed when a certain condition...

question_answer

Q: Please put into SOP form~xyz + yz + x~y

A: It is said that a Boolean expression consisting solely of Minterms (product terms) is in the form of...

question_answer

Q: Apply backtracking to the problem of finding a Hamiltonian circuit in the graph below:

A: Hamilton circuit, also called as Hamilton cycle forms a close loop by visiting each node exactly onc...

question_answer

Q: Write the MIPS assembly code that corresponds to the pseudo codebelow. Assume that the address for i...

A: MIPS instruction:The full form of MIPS is Million Instructions Per Second.The speed of computer’s pr...

question_answer

Q: Annotate the following MIPS instructions to indicate source registersand destination registers. A so...

A: Annotations for the MIPS instructions mentioned in the question are given below-add $s1, $t2, $t3Add...

question_answer

Q: Write an application to pre-sell a limited number of cinema tickets. Each buyer can buy as many as 4...

A: Create a java program to pre-sell the cinema ticket.The name of the program is TicketSeller.The maxi...

question_answer

Q: What is a nested function?  and what part in the following code is considered a nest function??     ...

A:  NOTE:Programming language is not mentioned in the question. The following explanations are given ba...

question_answer

Q: Arrays Write three statements to print the first three elements of array runTimes. Follow each state...

A: Note: As the user given index value is constant and so the value of index will not be changed while ...

question_answer

Q: Write a program that asks for the name of an input file. Then, read all the numbers in the file, and...

A: Create a PYTHON3 file in which import io module and validate file in program.Print sum, number of el...