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
Refrigerant-134a enters the expansion valve of a refrigeration system at 120 psia as a saturated liquid and leaves at 20 psia. D
Shkiper50 [21]

Solution :

$P_1 = 120 \ psia$

$P_2 = 20 \ psia$

Using the data table for refrigerant-134a at P = 120 psia

$h_1=h_f=40.8365 \ Btu/lbm$

$u_1=u_f=40.5485 \ Btu/lbm$

$T_{sat}=87.745^\circ  F$

∴ $h_2=h_1=40.8365 \ Btu/lbm$

For pressure, P = 20 psia

$h_{2f} = 11.445 \ Btu/lbm$

$h_{2g} = 102.73 \ Btu/lbm$

$u_{2f} = 11.401 \ Btu/lbm$

$u_{2g} = 94.3 \ Btu/lbm$

$T_2=T_{sat}=-2.43^\circ  F$

Change in temperature, $\Delta T = T_2-T_1$

                                         $\Delta T = -2.43-87.745$

                                           $\Delta T=-90.175^\circ  F$

Now we find the quality,

$h_2=h_f+x_2(h_g-h_f)$

$40.8365=11.445+x_2(91.282)$

$x_2=0.32198$

The final energy,

$u_2=u_f+x_2.u_{fg}$

   $=11.401+0.32198(82.898)$

   $=38.09297 \ Btu/lbm$

Change in internal energy  

$\Delta u= u_2-u_1$

   = 38.09297-40.5485

  = -2.4556        

5 0
2 years ago
the velocity of a particle is given by v=16t^2i+4t^3j+(5t+2k) m/s, where t is in seconds. if the particle is at the origin when
pshichka [43]

Answer:

80.16 m/s^2

at t=2 s

x=42.3 m

y=16 m

z=14 m

Explanation:

solution

The x,y,z components of the velocity are donated by the i,j,k vectors.

v_{x}=16t^{2}  \\v_{y}=4t^{3}\\v_{z}=5t+2

acceleration is a derivative of velocity with respect to time.

a_{x}=\frac{d}{dt} v_{x}=\frac{d}{dt}[16t^{2}]=32t\\a_{y}=\frac{d}{dt} v_{y}=\frac{d}{dt}[4t^{3}]=12t^{2} \\a_{z}=\frac{d}{dt} v_{z}=\frac{d}{dt}[5t+2]=5

evaluate acceleration at 2 seconds

a_{x} =32*2=64m/s^{2}\\ a_{y} =12*2^{2} =48m/s^{2}\\a_{z} =5m/s^{2}

the magnitude of the acceleration is the square root of the sum of the square of each component of the acceleration.

=\sqrt{a_{x}^2 +a_{y}^2+a_{z} ^2 } \\=\sqrt{64^2 +48^2+5 ^2 }\\=80.16m/s^2

position is the integral of velocity with respect to time position at a time can be found by taking by taking the definite intergral of each component.

x=\int\limits {v_{x} } \, dx=\int\limits^2_0 {{16t^2} \, dt=42.7m\\\\y=\int\limits {v_{y} } \, dx=\int\limits^2_0 {{4t^3} \, dt=16m\\\\\\\\\\z=\int\limits {v_{z} } \, dx=\int\limits^2_0 {{5t+2} \, dt=14m\\\\

3 0
3 years ago
Carbon dioxide steadily flows into a constant pressure heater at 300 K and 100 kPa witha mass flow rate of 9.2 kg/s. Heat transf
docker41 [41]

Answer:

Carbon dioxide temperature at exit is 317.69 K

Carbon dioxide flow rate at heater exit is 20.25 m³/s

Explanation:

Detailed steps are attached below.

8 0
3 years ago
How can we love our country? Not by words but by deeds. - Jose P. Laurel
Vadim26 [7]

Answer:

1. You have the courage to help without expecting a reward.

2. Because actions are more eloquent than words. Actions are far more valuable and counted than  words, and that's how she inspired me.

3. Doing simple things that can make someone grateful and happy  without knowing that someone is inspired and motivated by your good deeds, and also doing some interesting things By.

Explanation:

6 0
2 years ago
Find At Least Three Instances Of Set Constructions In Your CS Courses And Use Them To Exhibit All Set Operations Discussed In Cl
hoa [83]

An expertly designed format for arranging, processing, accessing, and storing data is called a data structure.

Data structures come in both simple and complex forms, all of which are made to organize data for a certain use. Users find it simple to access the data they need and use it appropriately thanks to data structures. The organizing of information is framed by data structures in a way that both machines and people can better grasp. A data structure may be chosen or created in computer science and computer programming to store data in order to be used with different methods. In some circumstances, the design of the data structure and the algorithm's fundamental operations are closely related. Each data structure comprises information about the data values, relationships between the data and — in some situations — functions that can be applied to the data. For instance, in an object-oriented programming language, the data structure and its related methods are tied together as part of a class description. Although they may be designed to operate with the data structure in non-object oriented languages, these functions are not considered to be a part of the data structure. A data structure may be chosen or created in computer science and computer programming to store data in order to be used with different methods. In some circumstances, the design of the data structure and the algorithm's fundamental operations are closely related. Each data structure comprises information about the data values, relationships between the data and — in some situations — functions that can be applied to the data.

Know more about data structure here:

brainly.com/question/29487957

#SPJ4

4 0
1 year ago
Other questions:
  • After informing his employer that he had cancer, Maury was abruptly fired. The federal legislation that prohibits discrimination
    6·1 answer
  • What are the advantages of using 3D ink jet printing?
    10·1 answer
  • Dr. Thermo, only has one bottle of neon. However, he needs to run two experiments, each requiring its own bottle. Therefore, he
    13·1 answer
  • Suppose an underground storage tank has been leaking for many years, contaminating a groundwater and causing a contaminant conce
    8·1 answer
  • A roller-coaster car is traveling at a speed of 23 m/s when it passes through point B. At that point, it enters a concave down c
    8·1 answer
  • A converging - diverging frictionless nozzle is used to accelerate an airstream emanating from a large chamber. The nozzle has a
    15·2 answers
  • A force 25 N makes an angle of 30,45 and 75 degree with x,y and z axis. What should be the corresponding force vector?
    8·1 answer
  • The annual average of solar photovoltaic energy in Phoenix is 6,720
    8·1 answer
  • What is wrong with the following code?<br> 6<br> print (what is your name?)
    9·2 answers
  • Which type of system is being researched to deliver power to several motors to drive multiple systems in vehicles?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!