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
ohaa [14]
3 years ago
8

Consider the following incomplete code segment, which is intended to print the sum of the digits in num. For example, when num i

s 12345, the code segment should print 15, which represents the sum 1 + 2 + 3 + 4 + 5.
int num = 12345;

int sum = 0;

/* missing loop header */

{

sum += num % 10;

num /= 10;

}

System.out.println(sum);

Which of the following should replace /* missing loop header */ so that the code segment will work as intended?

while (num > 0)

A

while (num >= 0)

B

while (num > 1)

C

while (num > 2)

D

while (num > sum)

E

Engineering
1 answer:
ValentinkaMS [17]3 years ago
6 0

Answer:

A) while (num >= 0)

Explanation:

To understand why we need to focus on the module and division operation inside the loop. num % 10 divide the number by ten and take its remainder to then add this remainder to sum, the important here is that we are adding up the number in reverse order and wee need to repeat this process until we get the first number (1%10 = 1), therefore, num need to be one to compute the last operation.

A) this is the correct option because num = 1 > 0 and the last operation will be performed, and after the last operation, num = 1 will be divided by 10 resulting in 0 and 0 is not greater than 0, therefore, the cycle end and the result will be printed.

B) This can not be the option because this way the program will never ends -> 0%10 = 0 and num = 0/10 = 0

C) This can not be the option because num = 1 > 1 will produce an early end of the loop printing an incomplete result

D) The same problem than C

E) There is a point, before the operations finish, where sum > num, this will produce an early end of the loop, printing an incomplete result

You might be interested in
A 10 hp motor is used to raise a 1000 Newton weight at a vertical distance of 5 meters. What is the work the motor performs?
Aleksandr [31]

The work done by a 10 HP motor when it raises a 1000 Newton weight at a vertical distance of 5 meters is <u>5kJ</u>.

Define work. Explain the rate of doing work.

Work is <u>the energy that is moved to or from an item by applying force along a displacement</u> in physics. For a constant force acting in the same direction as the motion, work is <u>easiest expressed as the product of </u><u>force </u><u>magnitude and distance traveled</u>.

Since the <u>force </u><u>transfers one unit of energy for every unit of </u><u>work </u><u>it performs</u>, the rate at which work is done and energy is used are equal.

Solution Explained:

Given,

Weight = 1000N and distance = 5m

A/Q, the work here is done in lifting then

Work = (weight) × (distance moved)

         = 1000 X 5

         = 5000Nm or 5000J = 5kJ

Therefore, the work done in lifting a 1000 Newton weight at a vertical distance of 5 meters is 5kJ.

To learn more about work, use the link given
brainly.com/question/25573309
#SPJ9

<u />

4 0
1 year ago
A pipe 100 mm dia and 1 km long is to carry water from a reservoir to a village of 1000 people consuming 200 l/person/day. The p
natka813 [3]

Answer:

i899999999999999999ijhhh

Explanation:

8 0
3 years ago
Read 2 more answers
Which two word pairs to locate the word vicious in the dictionary
Harman [31]

AnsweR Viciously comes from the adjective vicious, which originally meant "of the nature of vice, or wicked." The Latin root, vitiosus, means "faulty, defective, or corrupt."

Explanation:

5 0
3 years ago
If im 14 and your 14 what does that equal
Karo-lina-s [1.5K]

Answer:

hmmmmmmmmmmmmmmmmmmmmmmm

Explanation:

4 0
3 years ago
Read 2 more answers
A 0.2-m^3 rigid tank equipped with a pressure regulator contains steam at 2MPa and 320C. The steam in the tank is now heated. Th
prohojiy [21]

Answer:

Q=486.49 KJ/kg

Explanation:

Given that

V= 0.2 m³

At initial condition

P= 2 MPa

T=320 °C

Final condition

P= 2 MPa

T=540°C

From steam table

At P= 2 MPa and T=320 °C

h₁=3070.15 KJ/kg

At P= 2 MPa and T=540°C

h₂=3556.64  KJ/kg

So the heat transfer ,Q=h₂ - h₁

Q= 3556.64 - 3070.15  KJ/kg

Q=486.49 KJ/kg

7 0
3 years ago
Other questions:
  • If a torque of M = 300 N⋅m is applied to the flywheel, determine the force that must be developed in the hydraulic cylinder CD t
    13·1 answer
  • Technician A says that you don’t need to use an exhaust extraction system when working on vehicles equipped with a catalytic con
    9·1 answer
  • 7. Which power source is an important transition between
    7·1 answer
  • Describe three differences between liquids and gases in fluid power systems.<br> Help !!!
    5·1 answer
  • Write a program that prompts the user to enter time in 12-hour notation. The program then outputs the time in 24-hour notation.
    6·1 answer
  • Hi. I would like to know why one side of an island can get more rain (more rain forms), while the other gets less.
    15·2 answers
  • Scientific research techniques are used to analyze the effectiveness of political advertising. False True
    8·1 answer
  • What are the two (2) different design elements of scratch?
    10·1 answer
  • A kitchen contains one section of counter that's 20 inches
    7·1 answer
  • This test should be performed on all cord sets, receptacles that aren't part of a building or structure's permanent wiring, and
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!