1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
taurus [48]
3 years ago
11

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 k = 0;int prod = 1;while (k>=0){System.out.println("Enter a number: ");k= readInt( );prod = prod*k;}System.out.println("product: "+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
Computers and Technology
1 answer:
leonid [27]3 years ago
5 0

Answer:

Option D The negative number entered to signal no more input is included in the product

Explanation:

Given the code as follows:

  1.        int k = 0;
  2.        int prod = 1;
  3.        while (k>=0)
  4.        {
  5.            System.out.println("Enter a number: ");
  6.            k= readInt( );
  7.            prod = prod*k;
  8.        }
  9.        System.out.println("product: "+prod);

The line 7 is a logical error. Based on the while condition in Line 3, the loop shall be terminated if k smaller than zero (negative value). So negative value is a sentinel value of this while loop. However, if user enter the negative number to k, the sentinel value itself will be multiplied with prod in next line (Line 7) which result inaccurate prod value.

The correct code should be

  1.        int k = 0;
  2.        int prod = 1;
  3.        while (k>=0)
  4.        {
  5.            prod = prod*k;
  6.            System.out.println("Enter a number: ");
  7.            k= readInt( );
  8.        }
  9.        System.out.println("product: "+prod);
You might be interested in
When inserting a fly in animation what is the first step in the process?
weqwewe [10]

Answer:

you select the element you wish to animate

6 0
3 years ago
. Briefly describe an SQL DML statement for changing existing data in a table.
bearhunter [10]

Answer:

The Update statement in the DML is used for changing existing data in a table.

Explanation:

Their are following Sql statement in the DML.

Insert

This SQL statement is used for inserting data into the table.

select

This SQL statement is used for retrieving data from database  

update

This SQL statement is used for updating data in a table.

delete

This SQL statement is used for delete data from database .

The "UPDATE" SQL statement in DML is used for Modify the data in the existing table .

Following are the syntax of Update SQL query

Update tablename

set column1=value1,column2=value2............column N=valueN

Where condition;

Example :Suppose we have student table and (rollno,name,age and add) are the field for that table we have to change the address of rollno 105

Then we use update query like that

UPDATE STUDENT

SET add='kalam nagar'

where rollno=105;

8 0
3 years ago
I will give the brainly or whatever its called
igomit [66]

Answer:

Just answer everyones questions and youll be at the right rank in no time

Explanation:

5 0
3 years ago
Read 2 more answers
My mom works from home selling her craft work online to people all over the world. She can do this from home because we have acc
postnew [5]
The computer and a device
7 0
3 years ago
Read 2 more answers
Does any one know how to do addition of binary numbers​
Alla [95]

Answer:

The addition of binary numbers is done by adding the digits starting from the right side of the numbers, in the same way as we add two or more base 10 numbers. In binary addition, the place values are given as ones, twos, fours, eights, sixteens, etc.

Explanation:

3 0
3 years ago
Other questions:
  • Access controls are enforced automatically in FMS service routines that access and manipulate files and directories.
    9·1 answer
  • If you want to add a picture to your document, you can __________. (Select all that apply.)
    10·1 answer
  • A user is claiming a host can be reached via the IP address but not through the name. What should a technician do first to resol
    13·1 answer
  • Esther has acquired an associate's degree in information technology and certifications in PageMaker and Illustrator. Which caree
    8·2 answers
  • Show the subnet address, subnet mask in slash notation, broadcast address, number of addresses, first valid host address, and th
    13·1 answer
  • Joshua takes ownership of all his tasks. Which quality is he demonstrating?
    9·2 answers
  • the piece of hardware that contains the circuitry that processes the information coming in to the computer
    13·1 answer
  • A user purchased a new smart home device with embedded software and connected the device to a home network. The user then regist
    5·1 answer
  • What is Stefen Salvators mom name? For the tvd fans
    12·2 answers
  • In a finite state machine, state transitions happen only: a. When the reset causes a clock pulse on the D outputs of the flip-fl
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!