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
A piston–cylinder device containing carbon dioxide gas undergoes an isobaric process from 15 psia and 80°F to 170°F. Determine t
drek231 [11]

Answer:

See explanation

Explanation:

Given:

Initial pressure,

p

1

=

15

psia

Initial temperature,

T

1

=

80

∘

F

Final temperature,

T

2

=

200

∘

F

Find the gas constant and specific heat for carbon dioxide from the Properties Table of Ideal Gases.

R

=

0.04513

Btu/lbm.R

C

v

=

0.158

Btu/lbm.R

Find the work done during the isobaric process.

w

1

−

2

=

p

(

v

2

−

v

1

)

=

R

(

T

2

−

T

1

)

=

0.04513

(

200

−

80

)

w

1

−

2

=

5.4156

Btu/lbm

Find the change in internal energy during process.

Δ

u

1

−

2

=

C

v

(

T

2

−

T

1

)

=

0.158

(

200

−

80

)

=

18.96

Btu/lbm

Find the heat transfer during the process using the first law of thermodynamics.

q

1

−

2

=

w

1

−

2

+

Δ

u

1

−

2

=

5.4156

+

18.96

q

1

−

2

=

24.38

Btu/lbm

7 0
3 years ago
Pls help me answer my module
Otrada [13]

Answer:

Hand tools based on job requirement and its importance and the classification of hand tools according to its function and its importance are discussed below in details.

Explanation:

Hand tools based on work requirement is essential because Every tool is specifically invented for a particular purpose, so picking the accurate tool will also reduce the amount of energy needed to get work done right without causing injury or harm to either the tools or the exterior being worked on.

classifying of hand tools: wrenches, screwdrivers, cutters, striking tools, hammer tool or struck, pliers, vise, clamps, snips, saws, drills, and knives.

4 0
3 years ago
This manometer is used to measure the difference in water level between the two tanks.
SpyIntel [72]

Answer:

a) True

Explanation:

hope it helps u

3 0
2 years ago
Before taking off a plane travels at a speed of 1/4 km per second. The runaway is 5 km. How many seconds does it take the plane
Vikentia [17]

Answer:

1 5segundos

Explanation:

8 0
3 years ago
The maximum stress that a bar will withstand before failing is called • Rapture Strength • Yield Strength • Tensile Strength • B
konstantin123 [22]

Answer: Rupture strength

Explanation: Rupture strength is the strength of a material that is bearable till the point before the breakage by the tensile strength applied on it. This term is mentioned when there is a sort of deformation in the material due to tension.So, rupture will occur before whenever there are chances of failing and the material is still able to bear stresses before failing.  

7 0
3 years ago
Other questions:
  • A turbine produces shaft power from a gas that enters the turbine with a (static) temperature of 628 K, a velocity of 143 m/s an
    7·1 answer
  • What are the causes of electric shock​
    13·1 answer
  • What kind or kinds of engineers does take to design a drone and why?
    11·1 answer
  • WhT DO FILM PRODUTION SAY WHEN REMOVING GREEN AND BLUE SCREENS.
    14·1 answer
  • In the 5 Code of Federal Regulations (C.F.R.), it is recommended that an individual has security awareness training before s/he
    8·2 answers
  • Crest is to high, as through is to
    12·2 answers
  • What was the most important thing you learned this school year in your engineering class and why did you choose this thing
    15·1 answer
  • The diameter of a cylindrical water tank is Do and its height is H. The tank is filled with water, which is open to the atmosphe
    11·1 answer
  • How do you get your drivers lisnes when your 15
    8·1 answer
  • Were women treated as equals to men in early aviation history?
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!