Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education