Revise the code (Listing 5.4 Subtraction Quizloop.java) using the System.nanoTime() to measure the time in nano seconds.
Revise the code (Listing 5.4 Subtraction Quizloop.java) using the System.nanoTime() to measure the time in nano seconds.
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
Revise the code (Listing 5.4 Subtraction Quizloop.java) using the System.nanoTime() to measure the time in nano seconds.
![LISTING 5.4 SubtractionQuizLoop.java
1 import java.util. Scanner;
2
3 public class SubtractionQuizLoop (
public static void main(String[] args) {
final int NUMBER_OF_QUESTIONS = 5; 11 Number of questions
int correctCount = 0; 11 Count the number of correct answers
int count = 0; 1/ Count the number of questions
long startTime = System.currentTimeMillis();
String output = " "; // output string is initially empty
Scanner input = new Scanner (System. in);
4
5
6
8.
10
11
12
while (count < NUMBER_OF_QUESTIONS) {
/ 1. Generate two random single-digit integers
int numbert = (int) (Math. random () 10);
int number2 = (int) (Math.random ()* 10);
13
14
15
16
2. If number < number2, swap numbert with number2
if (number1 < number2) {
17
18
19
int temp = numbert;
number1 - number2;
number2 = temp;
20
21
22
23
! 3. Prompt the student to answer "What is number - number2?
System.out print (
"What is " + number1 +
int answer = input.nextInt ();
24
25
26
number2 + "? "):
27
28
I| 4. Grade the answer and display the result
if (number1 - number2 == answer ) {
System.out.printin("You are correct!");
correctCount++; I Increase the correct answer count
29
30
31
32
33
34
else
System.out.printin("Your answer is wrong. In" + number1
+ number2 + " should be " + (numbert - number2));
35
36
37
II Increase the question count
count++;
38
39
40
41
output += "\n" + number1
((number1 - number2 == answer) ? " correct":
number2 + "=" + answer +
42
wrong");
43
44
45
long endTime = System.currentTimeMillis();
long testTime = endTime - startTime;
46
47
System.out.printin("Correct count is "
"InTest time is " + testTi me / 1000 + " seconds\n" + output);
48
correctCount +
49
50
51 )](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F3d0b0572-8d36-4468-a5b0-740b909e03c0%2Fe4874ee5-2edc-4d70-a6b8-3edaa09a81f1%2F4zbjbc_processed.jpeg&w=3840&q=75)
Transcribed Image Text:LISTING 5.4 SubtractionQuizLoop.java
1 import java.util. Scanner;
2
3 public class SubtractionQuizLoop (
public static void main(String[] args) {
final int NUMBER_OF_QUESTIONS = 5; 11 Number of questions
int correctCount = 0; 11 Count the number of correct answers
int count = 0; 1/ Count the number of questions
long startTime = System.currentTimeMillis();
String output = " "; // output string is initially empty
Scanner input = new Scanner (System. in);
4
5
6
8.
10
11
12
while (count < NUMBER_OF_QUESTIONS) {
/ 1. Generate two random single-digit integers
int numbert = (int) (Math. random () 10);
int number2 = (int) (Math.random ()* 10);
13
14
15
16
2. If number < number2, swap numbert with number2
if (number1 < number2) {
17
18
19
int temp = numbert;
number1 - number2;
number2 = temp;
20
21
22
23
! 3. Prompt the student to answer "What is number - number2?
System.out print (
"What is " + number1 +
int answer = input.nextInt ();
24
25
26
number2 + "? "):
27
28
I| 4. Grade the answer and display the result
if (number1 - number2 == answer ) {
System.out.printin("You are correct!");
correctCount++; I Increase the correct answer count
29
30
31
32
33
34
else
System.out.printin("Your answer is wrong. In" + number1
+ number2 + " should be " + (numbert - number2));
35
36
37
II Increase the question count
count++;
38
39
40
41
output += "\n" + number1
((number1 - number2 == answer) ? " correct":
number2 + "=" + answer +
42
wrong");
43
44
45
long endTime = System.currentTimeMillis();
long testTime = endTime - startTime;
46
47
System.out.printin("Correct count is "
"InTest time is " + testTi me / 1000 + " seconds\n" + output);
48
correctCount +
49
50
51 )
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY