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
Durante el segundo trimestre de 2001, Tiger Woods fue el golfista que más dinero ganó en el PGATour. Sus ganancias sumaron un to
ehidna [41]

Answer: a. 0.4667

b. 0.4667 and C 0.0667

Explanation:

Given Data:

N = population size (10)

n = random selection (2)

r = number of observations = 7

Therefore

f(y) = ( r/y ) ( N - r / n - y ) / ( N /n )

When y = 1

f(1) = ( 7/1 ) ( 10 - 7 / 2 -1 ) / ( 10/2 )

= 7 / 15

= 0.4667

When y = 2

f(2) = ( 7/2 ) ( 10 - 7 / 2 -2 ) / ( 10/2 )

= 7 / 15

= 0.4667

When y = 0

f(0) = ( 7/0 ) ( 10 - 7 / 2 -0) / ( 10/2 )

= 1 / 15

= 0.0667

8 0
3 years ago
A particle moving on a straight line has acceleration a = 5-3t, and its velocity is 7 at time t = 2. If s(t) is the distance fro
Vikki [24]

Given acceleration a = 5-3t, and its velocity is 7 at time t = 2, the value of s2 - s1 = 7

<h3>How to solve for the value of s2 - s1</h3>

We have

= \frac{dv}{dt} =v't = 5-3t\\\\\int\limits^a_b {v'(t)} \, dt

= \int\limits^a_b {(5-3t)} \, dt

5t - \frac{3t^2}{2} +c

v2 = 5x2 -  3x2 + c

= 10-6+c

= 4+c

s(t) = \frac{5t^2}{2} -\frac{t^3}{2} +3t + c

S2 - S1

=(5*\frac{4}{2} -\frac{8}{2} +3*2*c)-(\frac{5}{2} *1^2-\frac{1^2}{2} +3*1*c)

= 6 + 6+c - 2+3+c

12+c-5+c = 0

7 = c

Read more on acceleration here: brainly.com/question/605631

5 0
2 years ago
Technician A says that a voltage drop of 0.8 volts on the starter ground circuit is within specifications. Technician B says tha
Romashka-Z-Leto [24]

Answer:

Technician A is wrong

Technician B is right

Explanation:

voltage drop of 0.8 volts on the starter ground circuit is not within specifications. Voltage drop should be within the range of 0.2 V to 0.6 V but not more than that.

A spun bearing can seize itself around the crankshaft journal causing it not to move. As the car ignition system is turned on, the stater may draw high current in order to counter this seizure.

8 0
3 years ago
LC3 Programming ProblemUse .BLKW to set up an array of 10 values, starting at memory location x4000, as in lab 4.Now programmati
irga5000 [103]

Answer:

Check the explanation

Explanation:

Code

.ORIG x4000

;load index

LD R1, IND

;increment R1

ADD R1, R1, #1

;store it in ind

ST R1, IND

;Loop to fill the remaining array

TEST LD R1, IND

;load 10

LD R2, NUM

;find tw0\'s complement

NOT R2, R2

ADD R2, R2, #1

;(IND-NUM)

ADD R1, R1, R2

;check (IND-NUM)>=0

BRzp GETELEM

;Get array base

LEA R0, ARRAY

;load index

LD R1, IND

;increment index

ADD R0, R0, R1

;store value in array

STR R1, R0,#0

;increment part

INCR

;Increment index

ADD R1, R1, #1

;store it in index

ST R1, IND

;go to test

BR TEST

;get the 6 in R2

;load base address

GETELEM LEA R0, ARRAY

;Set R1=0

AND R1, R1,#0

;Add R1 with 6

ADD R1, R1, #6

;Get the address

ADD R0, R0, R1

;Load the 6th element into R2

LDR R2, R0,#0

;Display array contents

PRINT

;set R1 = 0

AND R1, R1, #0

;Loop

;Get index

TOP ST R1, IND

;Load num

LD R3,NUM

;Find 2\'s complement

NOT R3, R3

ADD R3, R3,#1

;Find (IND-NUM)

ADD R1, R1,R3

;repeat until (IND-NUM)>=0

BRzp DONE

;load array address

LEA R0, ARRAY

;load index

LD R1, IND

;find address

ADD R3, R0, R1

;load value

LDR R1, R3,#0

;load 0x0030

LD R3, HEX

;convert value to hexadecimal

ADD R0, R1, R3

;display number

OUT

;GEt index

LD R1, IND

;increment index

ADD R1, R1, #1

;go to top

BR TOP

;stop

DONE HALT

;declaring variables

;set limit

NUM .FILL 10

;create array

ARRAY .BLKW 10 #0

;variable for index

IND .FILL 0

;hexadecimal value

HEX .FILL x0030

;stop

.END

7 0
3 years ago
The component of a regenerative vapor power cycle that permits only liquid to pass through to a region of lower pressure is a?
Zepler [3.9K]

The component of a regenerative vapor power cycle that permits only liquid to pass through to a region of lower pressure is a Valve/trap.

<h3>What is vapor?</h3>
  • In physics, a substance in the gas phase at a temperature lower than its critical temperature is referred to as a vapor or vapor.
  • This means that the vapor can be condensed to a liquid by increasing the pressure on it without decreasing the temperature.
  • An aerosol is distinct from a vapor.
  • A suspension of minute liquid, solid, or both types of particles in a gas is known as an aerosol.
<h3>Why does vapor form?</h3>
  • Evaporation or sublimation are two processes that can be used to create it.
  • Unlike clouds, fog, or mist, which are only suspended drops of liquid water in the atmosphere, watevaporur is a gas and cannot be seen.
  • In the atmosphere, water vapor frequently exists below the boiling point.

Learn more about vapor here:

brainly.com/question/14578189

#SPJ4

3 0
2 years ago
Other questions:
  • You have designed a treatment system for contaminant Z. The treatment system consists of a pipe that feeds into a CSTR. The pipe
    8·1 answer
  • Consider the fully developed flow of glycerin at 40°C through a 60-m-long, 4-cm-diameter, horizontal, circular pipe. If the flow
    15·1 answer
  • Two kilograms of air in a piston-cylinder assembly undergoes an isothermal process from an initial state of 200K, 300kPa to 600k
    8·1 answer
  • WILL BRAINLIEST IF CORRECT!!!!!<br><br> Some one help ASAP.
    8·1 answer
  • Define the coefficient of determination and discuss the impact you would expect it to have on your engineering decision-making b
    15·1 answer
  • 12. A structural component is fabricated from an alloy that has a plane strain fracture toughness of It has been determined that
    11·1 answer
  • Can U lose a rank in Brainly by using too many points?
    6·1 answer
  • The hot-wire anemometer.' A hot-wire anemome ter is essentially a fine wire, usually made of platinum,which is heated electrical
    6·1 answer
  • A wing generates a lift L when moving through sea-level air with a velocity U. How fast must the wing move through the air at an
    7·1 answer
  • 3.8 LAB - Select lesson schedule with multiple joins
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!