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
Engineering Careers Scavenger Hunt
emmasim [6.3K]

Answer:

c

Explanation:

it's the only engineering career

6 0
3 years ago
Read 2 more answers
Two balls are chosen randomly from an urn containing 8 white 4 black, and orange balls. Suppose that we win $ 2 for each black b
Scorpion4ik [409]
(-2,-10,-1,-2,-3,-4)
8 0
3 years ago
Identify an object in your house that contains a physical system and list three questions you could use to define the system
jonny [76]

Answer:

ALL CAREFULLY ANSWERED CORRECTLY

Explanation:

1) A loaf of Bread PHYSICAL SYSTEM

✓ How can the environment affect the edibility of the bread

✓ What are the constituents that makes up the bread

✓ What process is involved in these constituents mixing to form the loaf.

2) The law of thermodynamics makes us to understand that when heat/energy passes through a system, the systems internal energy changes with respect to the conservation of energy law. That is energy lost = energy gained. Typically, ice would melt in a cup of hot tea because of the thermal energy in the molecules of the hot tea. When you heat a material, you are adding thermal kinetic energy to its molecules and usually raising its temperature. The temperature of the ice raises due to the kinetic energy added to it and it melts to water.

3) The theory of systems view the world as a complex system of interconnected parts. If we consider the society; (financial systems, political systems, etc) we will agree that they individually have their own components and it's the summation of this components that makes the system, this implies that system thinking could be applicable in this kinda of systems as long as they are made up of components.

4) Technology has boosted every sector of our lives and it has the capacity to do more. Restricting it's importance to entertainment alone would be an underusing of its potentials. Engineering students infact should not need any drive to be encouraged about maximizing all it can do in shaping our world.

5) ~ Nature shows its splendid soul

~Never ceases to leave us in amazement

~And we are in love

4 0
3 years ago
A 4140 steel shaft, heat-treated to a minimum yield strength of 100 ksi, has a diameter of 1 7/16 in. The shaft rotates at 600 r
velikii [3]
Answer:










Explanation:



4140-40 I’d pick wood




I hope this helps! :)
4 0
3 years ago
Read 2 more answers
4) A steel tape is placed around the earth at the equator when the temperature is 0 C. What will the clearance between the tape
snow_lady [41]

Answer:

2102.1 m

Explanation:

Temperature at the equator = 0⁰

Radius of the earth = 6.37x10⁶

Required:

We how to find out what the clearance between tape and ground would be if temperature increases to 30 degrees.

Final temperature = ∆T = 303-273 = 30

S = 11x10^-6

The clearance R = Ro*S*∆T

=6.37x10⁶x 11x10^-6x30

= 2102.1m

Or 2.102 kilometers

Thank you

4 0
2 years ago
Other questions:
  • A 3-kg block rests on top of a 2-kg block supported by, but not attached to, a spring of constant 40 N/m. The upper block is sud
    14·2 answers
  • Write a modular program that finds the equation, area, and circumference of a circle, given the coordinates of the center of the
    11·1 answer
  • Water at 20 °C is flowing with velocity of 0.5 m/s between two parallel flat plates placed 1 cm apart. Determine the distances f
    5·1 answer
  • Plot the absorbance, A, versus the FeSCN2 concentration of the standard solutions (the values from your Pre-lab assignment). Fro
    7·1 answer
  • The underground cafe has an operating cash flow of $187,000 and a cash flow to creditors of $71,400 for the past year. During th
    12·1 answer
  • Carbon dioxide (CO2) expands isothermally at steady state with no irreversibilities through a turbine from 10 bar, 500 K to 2 ba
    15·1 answer
  • If you are involved in a collision and your vehicle is blocking the flow of traffic, you should
    5·1 answer
  • The formation of faults in Earth's crust is an effect. What causes faults to form in the crust? Global Positioning System sensor
    9·1 answer
  • Does anyone know what this is​
    10·2 answers
  • When converting liquid level units to sensor output signal units, you should first convert the liquid level units to _____ units
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!