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-.
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-.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question

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

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

Knowledge Booster
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.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education