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]
2 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]2 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
What is the ANSI B paper size also know as?
krek1111 [17]

Answer:

ANSI A sized paper is commonly referred to as Letter and ANSI B as Ledger or Tabloid.

Explanation:

7 0
2 years ago
Which of the following sentences uses the active voice
MrRa [10]

Answer: Last week, Nate and I counted all the inventory.

Explanation: all other choices are passive voices

this sentence follows a clear subject + verb + object construct that's why it is an active voice. In fact, sentences constructed in the active voice add impact to your writing. but on the other hand With passive voice, the subject is acted upon by the verb.

Ape x

7 0
2 years ago
Define spring stiffness and damping constant.
Naddika [18.5K]

Answer Explanation:

SPRING STIFFNESS :The stiffness of a body is a measure of resistance offered by an elastic body to deformation.it is denoted by K every object has some stiffness for spring the spring stiffness is the force required to cause unit deflection

DAMPING CONSTANT: the damping constant is a number decided by manufacturer that describes the material property. Damping is an influence within an oscillatory system that has the effect of restricting its oscillation

3 0
3 years ago
Write the work of an architectual engineer????​
valentinak56 [21]

An architectural engineer is a person who is responsible for studying and evaluating construction blueprints and designs. This is to determine if the design is feasible and if it is feasible to construct. Building styles and aesthetics should not be prioritized over the structural integrity and safety of a proposed building. Plan, construct, and prototype buildings, and be able to identify, analyze, and resolve issues with them as they arise.

<em>Hope this helps :)</em>

3 0
1 year ago
Read 2 more answers
Question #4
inn [45]

Answer:

Deconstruction

Explanation:

8 0
3 years ago
Other questions:
  • A flat-plate solar collector is 2 m long and 1 m wide and is inclined 60o to the horizontal. The cover plate is separated from t
    13·1 answer
  • An equal-tangent sag vertical curve (with a negative initial and a positive final grade) is designed for 55 mi/h. The PVI is at
    5·1 answer
  • A Gaussian random voltage X volts is input to a half-wave rectifier and the output voltage is Y = Xu (X) Volts were u (x) is the
    9·1 answer
  • Ball joints on a vehicle equipped with MacPherson struts are being inspected for wear. Which of the following would be the corre
    11·1 answer
  • In Illinois, once a person has obtained their boating education certificate what is the minimum age to operate a motorized vesse
    11·2 answers
  • A railroad runs form city A to city B, a distance of 800km, through mountainous terrain. The present one-way travel time (includ
    13·1 answer
  • A large building will need several different types of workmen to install and repair pipes for water, heating,
    10·1 answer
  • HOW TO CALCULATE MARGINAL RATE
    9·1 answer
  • Meaning of perfomance bond
    14·1 answer
  • Why would the shear stress be considered as the momentum flux.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!