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
Q10: Technician A says that nearly all brands of scan tools will pull DTCs from the ABS
Llana [10]

Hey! How are you? My name is Maria, 19 years old. Yesterday broke up with a guy, looking for casual sex.

Write me here and I will give you my phone number - *pofsex.com*

My nickname - Lovely

7 0
3 years ago
Which of the following describes all illustrations created by freehand?
Klio2033 [76]

extension lines,sketches,leader lines,dimensions describes all illustrations created by freehand.

5 0
3 years ago
Read 2 more answers
Compare and contrast the different forms of energy that are represented below:
Kitty [74]

Explanation:

1) Wind energy is generated through a wind turbine. When wind passes through the blades of wind mill, the blades of the wind mill tend to rotate. Due to the spinning of the rotor across the turbine, the kinetic energy from the wind is converted to electrical energy

2) Incase of wind energy, the consumption gets higher when there is more wind and would be zero incase of no movement of blades.

Incase of hydroelectric power, the generation is rather stable and consumption depends on the usage of power from the consumers

Incase of gasoline generator, the generation is also stable subject to availability of gasoline and consumption again depends on the usage of power from the consumers

3) Pros of Hydroelectric power

Cost of electricity generation is less

Can produce green energy

Produce mass volume of electricity

Cons of Hydroelectric power

Requires massive initial investement

Can be installed on certain demographical area

8 0
3 years ago
If angle A is a complement of angle B, angle B and angle C are vertical angles, and the supplement of C has a measure of 140°. F
Over [174]

Answer:

50°

Explanation:

Complementary angles add up to 90°.

Supplementary angles add up to 180°.

Vertical angles are equal.

A + B = 90°

B = C

C = 180° − 140°

C = 40°

B = 40°

A = 50°

7 0
3 years ago
Does anybody know how to take a screenshot on a HP pavilion computer?
Setler79 [48]

Answer:

I do i do it everyday

Explanation:

Press windows and prt sc at the same time

6 0
2 years ago
Other questions:
  • A soil had a liquid limit of 44, a plastic limit of 21, and a shrinkage limit of 14. In the summer, the in situ water content wa
    14·1 answer
  • Calculate the equivalent capacitance of the three series capacitors in Figure 12-1
    5·1 answer
  • An air conditioning system operating on reversed carnot cycle is required to remove heat from the house at a rate of 32kj/s to m
    5·1 answer
  • You apply a force of 19 lbs on to the end of a lever to lift a crate. The resistance of the load is 106 lbs. Calculate the
    13·1 answer
  • Employees cannot be held legally responsible for an environmental violation.
    14·1 answer
  • Select the correct answer. Jude is a mechanical engineer. He works in the automobile industry. He is creating a prototype of an
    13·1 answer
  • 10. Identify one material we Mine and what we make with that material
    6·1 answer
  • The hypotenuse of a 45° right triangle is
    5·1 answer
  • Engineering Specificaitons is ...
    9·1 answer
  • A. The ragion was colonized by European powers
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!