Question: Consider the following code segment. The code is intended to read nonnegative numbers and compute their product until a negative number is read; however, it
Consider the following code segment. The code is intended to read nonnegative numbers and compute their
product until a negative number is read; however, it does not work as intended. Assume that the readint
method correctly reads the next number from the input stream.
int ;
int prod ;
while
System.out.print enter a number: ;
readInt ; readInt reads the next number from input
prod prod ;
System.out.printlnproduct: prod ;
Which of the following best describes the error in the program?
A The variable prod is incorrectly initialized.
B The while condition always evaluates to false.
C The while condition always evaluates to true.
D The negative number entered to signal no more input is included in the product.
E If the user enters a zero, the computation of the product will be terminated prematurely.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
