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
.If aligned and continuous carbon fibers with a diameter of 6.90 micron are embedded within an epoxy, such that the bond strengt
Alina [70]

Answer:

the required minimum fiber length is 0.80365 mm

Explanation:

Given the data in the question;

Diameter D = 6.90 microns = 6.90 × 10⁻⁶ m

Bond strength ζ = 17 MPa

Shear yield strength ζ_y = 68 Mpa

tensile strength of carbon fibers 6t_{fiber = 3960 MPa.

To determine the minimum fiber length we make use of the following relation;

L = (6t_{fiber × D) / 2ζ

we substitute our given values into the equation;

L = ( 3960 × 6.90 × 10⁻⁶) / (2 × 17 )

L = 0.027324 / 34

L = 0.000803647 m

L = 0.000803647 × (1000) mm

L = 0.80365 mm

Therefore, the required minimum fiber length is 0.80365 mm

7 0
3 years ago
Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If user
Thepotemich [5.8K]

Answer:

import java.util.Scanner;

public class FindMatchValue {

  public static void main (String [] args) {

     Scanner scnr = new Scanner(System.in);

     final int NUM_VALS = 4;

     int[] userValues = new int[NUM_VALS];

     int i;

     int matchValue;

     int numMatches = -99; // Assign numMatches with 0 before your for loop

     matchValue = scnr.nextInt();

     for (i = 0; i < userValues.length; ++i) {

        userValues[i] = scnr.nextInt();

     }

     /* Your solution goes here */

         numMatches = 0;

     for (i = 0; i < userValues.length; ++i) {

        if(userValues[i] == matchValue) {

                       numMatches++;

                }

     }

     System.out.println("matchValue: " + matchValue + ", numMatches: " + numMatches);

  }

}

8 0
3 years ago
Two flat plates, separated by a space of 4 mm, are moving relative to each other at a velocity of 5 m/sec. The space between the
xenn [34]

Answer:

0.008

Explanation:

From the question, the parameters given are:

Velocity V = 5 m/s

Pressure = 10 pa

But pressure = F/A

10 = F/A

F = 10A

Substitute all the parameters into the formula below

Coefficient of viscosity (η) = F × r /[AV]

Where

F = tangential force,

r = distance between layers,

A = Area, and

V = velocity

(η) = 10A × 0.004 /[A × 5]

The A will cancel out

(η) = 10 × 0.004 /[5]

(η) = 0.04 /5

(η) = 0.008

Therefore, the coefficient of viscosity of the fluid is 0.008

5 0
3 years ago
What is this thing on my boat?
MaRussiya [10]
It may be an engine cooler, or it may be for the boats speed

But I think it is for cooling the engine down
5 0
3 years ago
How do engineering approach their work (how do they do to solve the problem).
Romashka-Z-Leto [24]

engineering approach their work by finding new solutions to their problems. like if two things dont go together in an invention, they will find another way

6 0
3 years ago
Other questions:
  • Admission to an aquarium is $14 per person. There is also an IMAX theatre in the building, which charges $8 per ticket for a 3D
    8·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
  • A steel rectangular tube has outside dimensions of 150 mm x 50 mm and a wall thickness of 4 mm. State the inside dimensions, the
    5·1 answer
  • A digital Filter is defined by the following difference equation:
    11·1 answer
  • i need jacket for my daughter who will be going on a girls scouts camping trip it cannot be bulky because she is limited to one
    8·2 answers
  • The pressure intensity at a point in a fluid is equal in all directions a.true b.false​
    12·1 answer
  • What is the ideal cooling system for low horsepower motor? For example1hp motor
    9·1 answer
  • Make a sketch of a simple mechanically expanded brake and indicate the forces ​ ​ acting on the leading shoe when the brake is a
    10·1 answer
  • <img src="https://tex.z-dn.net/?f=%5Cint%5Climits%5Ea_b%20%7B7x%7D%20%5C%2C%20dx" id="TexFormula1" title="\int\limits^a_b {7x} \
    8·1 answer
  • What does Enter key do?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!