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
I am trying to make a vacuum cannon but all I can use to get out the air is a speed pump to give air to bicycles. I need to make
Mrrafil [7]

We can actually deduce here that making a airtight seal will take different format. You can:

  • Use an epoxy-resin to create an airtight seal
  • Create a glass-metal airtight seal
  • Make a ceramic-metal airtight seal.

<h3>What is an airtight seal?</h3>

An airtight seal is actually known to be a seal or sealing that doesn't permit air or gas to pass through. Airtight seal are usually known as hermetic seal. They are usually applied to airtight glass containers but the advancement in technology has helped to broaden the materials.

We can see that epoxy-resin can used to create an airtight seal. They create airtight seals to copper, plastics, stainless steels, etc.

When making glass-metal airtight seal, the metal should compress round the solidified glass when it cools.

Learn more about airtight seal on brainly.com/question/14977167

#SPJ1

6 0
1 year ago
What is the primary damage control telephone circuit for
user100 [1]

Answer:

hsyghcjqg9ug9duyssatayfjzurldh

6 0
2 years ago
A discrete MOSFET common-source amplifier has RG = 2 MΩ, gm = 5 mA/V, ro = 100 kΩ, RD = 20kΩ, Cgs = 3pF, and Cgd = 0.5pF. The am
Papessa [141]

Answer:

a) -36.36 V/V

b) 15.17 kHz

c) 1.6 GHz

Explanation:

See attached picture.

7 0
3 years ago
Basil is installing a system in Toronto, Ontario where they are wide temperature variations. What is the TD of the system he’s i
marysya [2.9K]
In places with cold winters, space heating systems have a fundamental role in buildings. Without them, indoor temperatures would quickly become unsuitable for human occupancy. The local weather is one of the most important factors when designing a heating system; if two identical buildings are developed in Miami FL and New York City, the heating load will be much higher for the NYC property.

4 0
3 years ago
Can high throttle torque tend to open the throttle plate
koban [17]

Answer:

no

Explanation:

7 0
2 years ago
Other questions:
  • In a particular application involving airflow over a heated surface, the boundary layer temperature distribution may be approxim
    6·1 answer
  • How can endurance athletes best delay muscle fatigue during training? a. By avoiding sports drinks during exercise b. By eating
    6·2 answers
  • After a 65 newton weight has fallen freely from rest a vertical distance of 5.3 meters, the kinetic energy of the weight is
    12·1 answer
  • Wastewater flows into a once it is released into A floor drain
    11·1 answer
  • A flywheel made of Grade 30 cast iron (UTS = 217 MPa, UCS = 763 MPa, E = 100 GPa, density = 7100 Kg/m, Poisson's ratio = 0.26) h
    9·1 answer
  • Steam enters an adiabatic turbine at 8 MPa and 500C with a mass flow rate of 3
    11·1 answer
  • Practice finding the volume of a sphere.
    10·2 answers
  • Test if a number grade is an A (greater than or equal to 90). If so, print "Great!". Hint: Grades may be decimals. Sample Run En
    15·1 answer
  • A 1/4" nut driver with a 1.52 inch diameter handle is used to install a 14" 6 UNC
    13·1 answer
  • Which type of engineer is needed in the following scenario?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!