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
patriot [66]
3 years ago
13

A store sells rope only in whole-foot increments. Given three lengths of rope, in feet, the following code segment is intended t

o display the minimum length of rope, in feet, that must be purchased so that the rope is long enough to be cut into the three lengths. For example, for lengths of 2.8 feet, 3 feet, and 5 feet, the minimum length of rope that must be purchased is 11 feet. For these inputs, the code segment should display 11. As another example, for lengths of 1.1 feet, 3.2 feet, and 2 feet, the minimum length of rope that must be purchased is 7 feet. For these inputs, the code segment should display 7.
double len1
double len2 double len3; double total = lenl + len2 + len3; int minLength = (int) (total + 0.5); System.out.print(minLength);
Which of the following best describes the behavior of the code segment?
1. The code segment works as intended for all nonnegative values of lent, len2, and len3.
2. The code segment does not work as intended for some values of lent, len2, and len3. It could be corrected by casting lent, len2, and len3 to int before adding them together and assigning the sum to minLength. The code segment does not work as intended for any values of lent, len2, and len3. It returns the sum of 0.5 and the three lengths for all values of lent, len2, and len3. 3. The code segment works as intended but only when the sum of the three lengths is an integer or the decimal part of the sum of the three lengths is greater than or equal to 0.5. 4. The code segment does not work as intended for some values of lent, len2, and len3. It could be corrected by declaring minLength as a double and casting it to an int in the System.out.print statement.
Computers and Technology
2 answers:
Nonamiya [84]3 years ago
7 0

Answer:

The correct option is option 3 which is The code segment works as intended but only when the sum of the three lengths is an integer or the decimal part of the sum of the three lengths is greater than or equal to 0.5.

Explanation:

As the variable minLength is defined as an integer thus the value is being truncated although the value of 0.5 is being added however if the decimal portion of the length is less than 0.5, the portion is truncated.

VikaD [51]3 years ago
5 0

Answer:

Answer is option 3) The code segment works as intended but only when the sum of the three lengths is an integer or the decimal part of the sum of the three lengths is greater than or equal to 0.5. Therefore,

Refer below for the explanation.

Explanation:

As the integer minlength that will result as final output illustrates that the integer of three ropes added 0.5 in the final output minlength.

You might be interested in
You are setting up a small network. The customer has decided to change his internet service provider (ISP) to EtherSpeed. The IS
salantis [7]

Home pc1 becouse it is the right one

3 0
3 years ago
A computer has dose not have ___________
Ksivusya [100]

Answer:

A computer does not have brain of its own

4 0
2 years ago
Read 2 more answers
Approximately what percentage of the world population owns a smartphone?
Usimov [2.4K]
The number of smartphone users is forcast to grow from 2.1 billion in 2016 to around 2.5 billion in 2019, with smartphone penetration rates increasing as well.over 36% of the worlds population is projected to use a smartphone by 2018, thats up from about 10% in 2011
5 0
3 years ago
What does obsolete mean?
Alex
No longer produced or used; out of date.
8 0
3 years ago
Read 2 more answers
I’m so lost. which username do i do.
koban [17]

Answer:

the username you feel like using

5 0
3 years ago
Read 2 more answers
Other questions:
  • Write a function M-file that takes as input two matrices A and B, and as output produces
    8·1 answer
  • "the magical number seven, plus or minus two" refers to the storage capacity of ________ memory.
    5·2 answers
  • Write a function called printBackwards() that will work with a C string. The function will print any C string backwards. You don
    13·1 answer
  • ____ is the official web portal for the U.S. government, providing access to all official U.S. government services and informati
    12·1 answer
  • Anybody know this question???
    6·1 answer
  • Choose the best type of loop for each situation.
    6·1 answer
  • To move an object to the bottom of the stack, click the Send Backwards arrow and then click Send to Back in the Arrange group on
    7·1 answer
  • What are the peripherals of a computer ​
    12·1 answer
  • Suppose you want to boot a VM from its virtual DVD drive, but it boots to the VM’s hard drive. Which of the following could be t
    12·1 answer
  • What was the name of first computer?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!