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 need help on the Coderz Challenge missions 3 part 3. PLEASE HELP!
allsm [11]

Answer:

the answer how you analyzs the problwm

6 0
3 years ago
Read 2 more answers
A fully braced structural member in a building is subjected to several different loads, including roof loads of D = 5 k and L_r
allochka39001 [22]

Answer: 37.4K

Explanation:

See attachment

7 0
3 years ago
Which of these are not referenced in an assembly?
Otrada [13]
E. Parts they don’t resemble
7 0
3 years ago
Why is the back-work ratio much higher in the brayton cycle than in the rankine cycle?
zloy xaker [14]

The back-work ratio much higher in the Brayton cycle than in the Rankine cycle because a gas cycle is the Brayton cycle, while a steam cycle is the Rankine cycle. Particularly, the creation of water droplets will be a constraint on the steam turbine's efficiency. Since gas has a bigger specific volume than steam, the compressor will have to work harder while using gas.

<h3>What are modern Brayton engines?</h3>

Even originally Brayton exclusively produced piston engines, modern Brayton engines are virtually invariably of the turbine variety. Brayton engines are also gas turbines.

<h3>What is the ranking cycle?</h3>

A gas cycle is the Brayton cycle, while the Ranking cycle is a steam cycle. The production of water droplets will especially decrease the steam turbine's performance. Gas-powered compressors will have to do more work since gas's specific volume is greater than steam's.

Th

To know more about Rankine cycle, visit: brainly.com/question/13040242

#SPJ4

4 0
1 year ago
If you are driving a 30-foot
Ratling [72]

Answer:

3 sec

If you are driving a 30-foot vehicle at 55 mph, how many seconds of following distance should you allow? 30ft truck. = 3 sec. Since the truck is over 40 mph.

Explanation:

5 0
3 years ago
Other questions:
  • Your driver license will be _____ if you race another driver on a public road, commit a felony using a motor vehicle, or are fou
    6·2 answers
  • A ring-shaped seal, made from a viscoelastic material, is used to seal a joint between two rigid pipes. When incorporated in the
    5·1 answer
  • Please help me fast, I don’t have time
    15·1 answer
  • The steel 4140 steel contains 0.4% C, however, it shows higher yield strength and ultimate strength than that of the 1045 (0.45%
    14·1 answer
  • What happens when force is placed on a square/rectangle?
    8·2 answers
  • You are using a Geiger counter to measure the activity of a radioactive substance over the course of several minutes. If the rea
    6·1 answer
  • - If you overload the rear portion of you vehicle &amp; it's raining out, your car could easily:
    14·1 answer
  • I just wanted to say thanks you to Brainly. This website is a huge help!
    12·1 answer
  • Ughhh my cramps hurt sm
    8·2 answers
  • The primary of an ideal transformer has 400 turns and its secondary has 200 turns. Neglecting electrical losses, if the power in
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!