Consider the following code: import acm.program.*; 02 public class Average extends CommandlineProgram 03 04 { 05 private static final int SENTINEL = -1; 06 public void run() { println("This program averages numbers."); int total = 0; int count = 0; 07 08 09 10 11 int num = readInt("Enter an integer (-1 to quit): "); while (num != SENTINEL) 12 13 { total = total + num; 14 15 count++; num = readInt("Enter an integer (-1 to quit): "); } if (count != 0) 16 17 18 19 { double average = total / (double) count; printin("Average is: " + average); } 20 21 22 23 24 else { println("Goodbye!"); 25 26 27 28 29 } What is the purpose of the condition check in the if statement on line 19? O To re-prompt the user for a number if they enter -1. To compute the average of all numbers after the user has entered a value of 0. O To avoid computing any average if the user enters a value of 0. O To avoid computing any average if the user only entered-.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question
Consider the following code:
01
import acm.program.*;
02
public class Average extends CommandlineProgram
{
private static final int SENTINEL = -1;
03
04
05
06
07
public void run()
{
println("This program averages numbers.");
int total = 0;
08
09
10
11
int count = 0;
int num = readInt("Enter an integer (-1 to quit): ");
12
while (num != SENTINEL)
{
total - total + num;
count++;
num = readInt("Enter an integer (-1 to quit): ");
}
if (count != e)
13
14
15
16
17
18
19
{
double average = total / (double) count;
println("Average is:
}
20
21
22
+ average);
23
24
else
{
printin("Goodbye!");
}
}
25
26
27
28
29
}
What is the purpose of the condition check in the if statement on line 19 ?
To re-prompt the user for a number if they enter -1.
To compute the average of all numbers after the user has entered a value of 0.
To avoid computing any average if the user enters a value of 0.
To avoid computing any average if the user only entered -1
O000
Transcribed Image Text:Consider the following code: 01 import acm.program.*; 02 public class Average extends CommandlineProgram { private static final int SENTINEL = -1; 03 04 05 06 07 public void run() { println("This program averages numbers."); int total = 0; 08 09 10 11 int count = 0; int num = readInt("Enter an integer (-1 to quit): "); 12 while (num != SENTINEL) { total - total + num; count++; num = readInt("Enter an integer (-1 to quit): "); } if (count != e) 13 14 15 16 17 18 19 { double average = total / (double) count; println("Average is: } 20 21 22 + average); 23 24 else { printin("Goodbye!"); } } 25 26 27 28 29 } What is the purpose of the condition check in the if statement on line 19 ? To re-prompt the user for a number if they enter -1. To compute the average of all numbers after the user has entered a value of 0. To avoid computing any average if the user enters a value of 0. To avoid computing any average if the user only entered -1 O000
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Hiring Problem
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,