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
Before turning in a test, it would be best to
Blababa [14]

Answer: D mate

Explanation:

4 0
3 years ago
Read 2 more answers
Two loads connected in parallel draw a total of 2.4 kW at 0.8 pf lagging from a 120-V rms, 60-Hz line. One load absorbs 1.5 kW a
stealth61 [152]

Answer: a) 0.948 b) 117.5µf

Explanation:

Given the load, a total of 2.4kw and 0.8pf

V= 120V, 60 Hz

P= 2.4 kw, cos θ= 80

P= S sin θ - (p/cos θ) sin θ

= P tan θ(cos^-1 (0.8)

=2.4 tan(36.87)= 1.8KVAR

S= 2.4 + j1. 8KVA

1 load absorbs 1.5 kW at 0.707 pf lagging

P= 1.5 kW, cos θ= 0.707 and θ=45 degree

Q= Ptan θ= tan 45°

Q=P=1.5kw

S1= 1.5 +1.5j KVA

S1 + S2= S

2.4+j1.8= 1.5+1.5j + S2

S2= 0.9 + 0.3j KVA

S2= 0.949= 18.43 °

Pf= cos(18.43°) = 0.948

b.) pf to 0.9, a capacitor is needed.

Pf = 0.9

Cos θ= 0.9

θ= 25.84 °

(WC) V^2= P (tan θ1 - tan θ2)

C= 2400 ( tan (36. 87°) - tan (25.84°)) /2 πf × 120^2

f=60, π=22/7

C= 117.5µf

7 0
3 years ago
Which two is right about febuary 14
igor_vitrenko [27]

Answer:A and B

Explanation:

3 0
3 years ago
Read 2 more answers
A satellite is launched 600 km from the surface of the earth, with an initial velocity of 8333.3 m./s, acting parallel to the ta
Vikki [24]

Answer:

eccentrcity of orbit is 0.22

Explanation:

GIVEN DATA:

Initial velocity of satellite = 8333.3 m/s

distance from the sun is 600 km

radius of earth is 6378 km

as satellite is acting parallel to the earth therefore\theta angle = 0

and radial component of given velocity is zero

we haveh = r_o v_r_o = 6378+600 =6.97*10^6 m

h = 6.97*10^6 *8333.3 = 58.08*10^9 m^2/s

we know that

\frac{1}{r} =\frac{GM}{h^2} \times ( i + \epsilon cos\theta)

GM = gr^2 = 9.81*(6.37*10^6)^2 = 398*10^{12} m^3/s

so

\frac{1}{6.97*10^6} =\frac{398*10^{12}}{(58.08*10^9)^2} \times ( i + \epsilon cos0)

solvingt for \epsilon)

\epsilon = 0.22)

therefore eccentrcity of orbit is 0.22

6 0
3 years ago
A(n)___ branch circuit supplies two or more receptacles or outlets for lighting and appliances
Juli2301 [7.4K]

Answer: General purpose branch circuit

Explanation:

General purpose branch circuit are the type of circuits that are used mainly to supply light to two or more receptacle outlets for small appliances. This circuits are about 120v can be used either in residential, commercial and industrial buildings.

6 0
3 years ago
Other questions:
  • Carbon dioxide (CO2) at 1 bar, 300 K enters a compressor operating at steady state and is compressed adiabatically to an exit st
    11·1 answer
  • Suppose you are implementing a relational employee database, where the database is a list of tuples formed by the names, the pho
    14·1 answer
  • You live on a street that runs East to West. You just had 2 inche of snow and you live on the North side of the street. You retu
    14·1 answer
  • This is a multi-part question. Once an answer is submitted, you will be unable to return to this part As steam is slowly injecte
    15·1 answer
  • A piston-cylinder device contains 0.15 kg of air initially at 2 MPa and 350 °C. The air is first expanded isothermally to 500 kP
    15·1 answer
  • According to the eNotes, a program that eliminates sales and promotions in an effort to minimize the bullwhip effect would be ca
    13·1 answer
  • A subsurface exploration report shows that the average water content of a fine-grained soil in a proposed borrow area is 22% and
    9·1 answer
  • What is the condition for maximum efficiency in a DC motor?
    15·1 answer
  • Is it permissible to install recessed fixture directly against wood ceiling joists? Explain why or why not.
    5·1 answer
  • How to pass sharp edged tools to another student in welding
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!