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
The thrust angle is checked by referencing
anygoal [31]

In Engineering, the thrust angle is checked by referencing: C. vehicle centerline.

<h3>What is a thrust angle?</h3>

A thrust angle can be defined as an imaginary line which is drawn perpendicularly from the centerline of the rear axle of a vehicle, down the centerline.

This ultimately implies that, the thrust angle is a reference to the centerline (wheelbase) of a vehicle, and it confirms that the two wheels on both sides are properly angled within specification.

Read more on thrust angle here: brainly.com/question/13000914

#SPJ1

5 0
2 years ago
The input and output signals of a system is related by the following equation: fraction numerator d squared y over denominator d
Colt1911 [192]

Answer:

Explanation:

The given equation is :

\frac{d^{2}y }{dx^{2} } + sin(3y) \frac{dy}{dt} + y = t\frac{df}{dt} + f

5 0
3 years ago
Consider a very long rectangular fin attached to a flat surface such that the temperature at the end of the fin is essentially t
zepelin [54]

Answer:

attached below

Explanation:

4 0
3 years ago
In a much smaller model of the Gizmo apparatus, a 5 kg mass drops 86 mm (0.086 m) and raises the temperature of 1 gram of water
Orlov [11]

Answer:

The amount of energy transferred to the water is 4.214 J

Explanation:

The given parameters are;

The mass of the object that drops = 5 kg

The height from which it drops = 86 mm (0.086 m)

The potential energy P.E. is given by the following formula

P.E = m·g·h

Where;

m = The mass of the object = 5 kg

g = The acceleration de to gravity = 9.8 m/s²

h = The height from which the object is dropped = 0.086 m

Therefore;

P.E. = 5 kg × 9.8 m/s² × 0.086 m = 4.214 J

Given that the potential energy is converted into heat energy, that raises the 1 g of water by 1°C, we have;

The amount of energy transferred to the water = The potential energy, P.E. = 4.214 J.

6 0
2 years ago
Metal and dirt are not considered contaminants to oll.<br> A) O True<br> B) O False
Likurg_2 [28]

Answer:

true

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • Line layout is also called ......​
    5·1 answer
  • Practice Problem: True Stress and Strain A cylindrical specimen of a metal alloy 49.9 mm long and 9.72 mm in diameter is stresse
    13·1 answer
  • All of the following are categories for clutch covers except
    11·1 answer
  • Who is father of Engineer?
    9·2 answers
  • What is the line called that has the red arrow pointing to it in the attached picture?
    6·1 answer
  • Two identical bulbs in parallel in a radio create a total resistance of 15 ohms in the circuit. What's the resistance of each of
    6·1 answer
  • What would happen if the brake pedal was released while the bleed screw was open during brake bleeding?
    7·1 answer
  • Please look at the attachments and help me with these questions
    7·1 answer
  • What factors need to be considered when building housing on a waterway
    10·2 answers
  • 12. What procedure should you follow when taking measurements?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!