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
Primary mental skills needed for riding a motorcycle
Irina-Kira [14]

Answer:

You have to know the basic mechanics to help you correctly use the motorcycle, and you also have to have the right mindset - knowing you can ride it, and having determination. All of these factors are the primary mental skills you need for riding a motorcycle.

5 0
2 years ago
The loneliest people are to kindest
valkas [14]

Answer:

The most damaged people are the wisest is a fact

Explanation:

5 0
3 years ago
Read 2 more answers
What are some advantages of generating electrical energy from tides instead of from fossil fuels
harina [27]

Answer:

Efficent at low speeds.

Explanation:

Since water is 1,000 times more dense than air, electricity can generated from tides much more efficiently at slower speeds than wind turbines can.

7 0
3 years ago
Using an "AND" and an "OR", list all information (Equipment Number, Equipment Type, Seat Capacity, Fuel Capacity, and Miles per
Tomtit [17]

Answer:

Explanation :

The given  information to be listed can are Equipment Number, Equipment Type, Seat Capacity, Fuel Capacity, and Miles per Gallon.

Check the attached document for the solution.

5 0
3 years ago
Un mol de gas ideal realiza un trabajo de 3000 J sobre su entorno, cuando se expande de manera isotermica a una temperatura de 5
Shkiper50 [21]

Answer:

74,4 litros

Explanation:

Dado que

W = nRT ln (Vf / Vi)

W = 3000J

R = 8,314 JK-1mol-1

T = 58 + 273 = 331 K

Vf = desconocido

Vi = 25 L

W / nRT = ln (Vf / Vi)

W / nRT = 2.303 log (Vf / Vi)

W / nRT * 1 / 2.303 = log (Vf / Vi)

Vf / Vi = Antilog (W / nRT * 1 / 2.303)

Vf = Antilog (W / nRT * 1 / 2.303) * Vi

Vf = Antilog (3000/1 * 8,314 * 331 * 1 / 2,303) * 25

Vf = 74,4 litros

3 0
3 years ago
Other questions:
  • 1. A pipeline constructed of carbon steel failed after 3 years of operation. On examination it was found that the wall thickness
    13·1 answer
  • Capitol Brewing Inc.'s management is very concerned with declining sales of their major product, a dark ale, and has asked for h
    14·1 answer
  • Make a proposal to add a small pizza shop to a historical part of town. How could it be designed to “fit” into the area?
    7·2 answers
  • A field sample of an unconfined aquifer is packed in a test cylinder. The length and diameter of the cylinder are 50 cm and 6 cm
    9·1 answer
  • In an experiment, the local heat transfer over a flat plate were correlated in the form of local Nusselt number as expressed by
    5·1 answer
  • The Acme tool is aligned to the work with: A. A square B. The eye C. An Acme tool gage D. A center gage
    14·1 answer
  • Hi im ***ar and im doing sculptural but what should it be about star wars or Marvel
    9·1 answer
  • I really need help i will give brainly plz no funny answers
    14·1 answer
  • For a bolted assembly with eight bolts, the stiffness of each bolt is kb = 1.0 MN/mm and the stiffness of the members is km = 2.
    14·1 answer
  • Precast concrete curtain wall panels: Group of answer choices are typically manufactured on site and then hoisted into place. of
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!