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-.
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
Related questions
Question
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.Similar questions
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,