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
Natali5045456 [20]
3 years ago
12

Declare a variable of type int. Prompt the user for a positive three-digit number. Test to ensure the number is within the prope

r bounds. If the number is larger or less than three digits, output "Error" and terminate the program. Otherwise, calculate and print the sum of the three digits.

Engineering
2 answers:
Sindrei [870]3 years ago
8 0

Answer:

// Scanner class is imported to allow program

// receive input

import java.util.Scanner;

// Solution class is defined

public class Solution {

   // main method that signify beginning of program execution

   public static void main(String args[]) {

       // Scanner object scan is created

       // it receive input via keyboard

       Scanner scan = new Scanner(System.in);

       // Prompt is display asking the user to enter number

       System.out.println("Enter your three digit number: ");

       // the user input is stored at userInput

       int userInput = scan.nextInt();

       // if-statement that check if user input is three digit

       if(userInput < 100 || userInput > 999){

           // if input is three digit; it display error

           System.out.println("Error");

       } else{

           // the first digit is gotten as the quotient

           // when the input is divided by 100

           int firstDigit = userInput / 100;

           // the second digit is gotten by dividing the

           // result of the input modulus 100 by 10

           int secondDigit = (userInput % 100) / 10;

           // the third digit is gotten through

           // userInput modulus 10

           int thirdDigit = userInput % 10;

           // the addition of the three digit is assigned to sum

           int sum = firstDigit + secondDigit + thirdDigit;

           // the sum is displayed to the user

           System.out.println("The sum of the three digit is: " + sum);

       }

   }

}

Explanation:

The program is well commented and detailed. Images showing output of the program is attached.

vredina [299]3 years ago
6 0
<h2>Answer:</h2>

//import the Scanner class to allow for user's inputs

import java.util.Scanner;

//Declare a class for the application

public class ThreeDigit {

   //Declare a main method where execution begins

   public static void main(String[] args) {

       //Create an object of the Scanner class to allow user's inputs

       Scanner input = new Scanner(System.in);

       

       //Prompt the user to enter a 3-digit number

       System.out.println("Enter a positive three-digit number");

       

       //Receive the number with the scanner object created

       //And store it in an int variable

       int num = input.nextInt();

       

       //Check if the number is within range.

       //A 3-digit number is between 99 and 1000

       //If it is within range

       if(num > 99 && num < 1000){

           

           //GET THE FIRST DIGIT

           //The first digit is the result of  

           //the integer division of the 3-digit number with 100

           int fdigit = num / 100;

           

           //GET THE SECOND DIGIT

           //The second digit is the result of  the integer division of the

           // remainder, when the 3-digit number is divided by 100,

           // with 10 .

           int sdigit = (num%100) / 10;

           

           //GET THE THIRD DIGIT

           //The third digit is the remainder when the 3-digit number is divided

           // by 10 .

           int tdigit = (num % 10);

           

           //Sum the three digits

           int sum = fdigit + sdigit + tdigit;

           

           

           //print out the result

           System.out.println("The sum of the three digits is : " + sum);

       

       }          //End of if statement  

       

       //If it is not within range

       else {

           //print out an error message

           System.out.println("Error");

       }           // End of else statement

       

       

   }           //End of main method

   

}       //End of class declaration

===========================================================

<h2>Sample Output 1:</h2>

>> Enter a positive three-digit number

345

>> The sum of the three digits is : 12

============================================================

<h2>Sample Output 2:</h2>

>> Enter a positive three-digit number

5678

>> Error

============================================================

<h2>Explanation:</h2>

The code has been written in Java. It contains comments explaining every segment of the code. Kindly go through the comments.

The actual lines of code are written in bold face to separate them from comments.

Sample outputs have also been provided to give a feel of what the program outputs.

You might be interested in
Identify five safety hazards that should be included in the design of the school
erik [133]

Answer:

1) function of fire doors and making sure theyre properly wired to fire alarms

2) proper water piping and purifaction for water fountains and sinks.

3)  falty sprinkler systems/rsuty sprikler systems that wont work

4) weather durable roofing and walls for storms and snow depending on were your located .

5) rsuted pipes in showers or fountains that could give you tetnus or other disaeases

Explanation:

HOPE THIS HELPS good luck!!

7 0
3 years ago
A turntable A is built into a stage for use in a theatrical production. It is observed during a rehearsal that a trunk B starts
lions [1.4K]

Answer:

The coefficient of static friction, μₛ, between the trunk and turntable = 0.32

Explanation:

For this motion of the trunk B,

Initial velocity, v₀ = 0

Tangential Acceleration, a = 0.28 m/s²

Time taken, t = 10s

Using equations of motion,

v = v₀ + at

v = 0 + 0.28 × 10 = 2.8 m/s

Frictional force, Fᵣ = μₛN

μₛ = coefficient of static friction,

N = Normal reaction exerted on the trunk B as a result of its weight = mg

Doing a force balance on the trunk B,

Force keeping the trunk B in circular motion must balance the frictional forces.

Force keeping the trunk B in circular motion, F = mv²/r

Fᵣ = F

μₛN = mv²/r but N = mg

μₛmg = mv²/r

μₛg = v²/r

μₛ = v²/gr

μₛ = 2.8²/(9.8 × 2.5) = 0.32

Hope this helps!!!

3 0
3 years ago
The following median grain size data were obtained during isothermal liquid phase sintering of an 82W-8Mo-8Ni-2Fe alloy. What is
Morgarella [4.7K]

Answer:

The probable grain-coarsening mechanism is : Ideal grain growth mechanism

( d^{2}- d_{0} ^{2} = kt )

Explanation:

The plot attached below shows the time dependence of the growth of grain.

The probable grain-coarsening mechanism is : Ideal grain growth mechanism

the ideal growth follows this principle = d^{2} - d^{2} _{0}  = kt

d = final grain size

d_{0} = initial grain size

k = constant ( temperature dependent )

t = 0

8 0
3 years ago
One kilogram of air, initially at 5 bar, 350 K, and 3 kg of carbon dioxide (CO2), initially at 2 bar, 450 K, are confined to opp
pentagon [3]

Answer:

Check the explanation

Explanation:

Energy alance of 2 closed systems: Heat from CO2 equals the heat that is added to air in

m_{a} c_{v,a}(T_{eq} -T_{a,i)} =m_{co2} c_{v,co2} (T_{co2,i} -T_{eq)}

1x0.723x(T_{eq} -350)=3x0.780x(450-T_{eq} ) ⇒T_{eq} = 426.4 °K

The initail volumes of the gases can be determined by the ideal gas equation of state,

V_{a,i}  = \frac{mRT_{a,i} }{P_{a,i} }=  \frac{1x (8.314 28.97 kJ kg • °K)x 350°K}{5 bar x 100KPa bar} = 0.201m^{3}

The equilibrium pressure of the gases can also be obtained by the ideal gas equation

P_{eq=\frac{(m_{a}R_{a}T_{eq})+(m_{a}R_{a}T_{eq} ) }{(V_{a,eq}+V_{CO2,eq)} } =\frac{(m_{a}R_{a}T_{eq})+(m_{a}R_{a}T_{eq} ) }{(V_{a,i}+V_{CO2,i)} }

P_{eq}= 1x(8.314 28.97)x426.4+3x(8.314 44)x426.4

                             (0.201+1.275)

= 246.67 KPa = 2.47 bar

6 0
3 years ago
A liquid jet vj of diameter dj strikes a fixed cone and deflects back as a conical sheet at the same velocity. find the cone ang
dmitriy555 [2]

Answer:

lol i cant real it sorry

Explanation:

7 0
2 years ago
Other questions:
  • Does a thicker core make an electromagnet stronger?
    13·1 answer
  • The boiler pressure is 38bar and the condenser pressure 0.032 bar.The saturated steam is superheated to 420 oC before entering t
    8·1 answer
  • What is the stress concentration factor of a shaft in torsion, where D=1.25 in. and d=1 in. and the fillet radius is, r=0.2 in.a
    7·1 answer
  • What is the Principle of Entropy Increase?
    9·1 answer
  • The heat flux through a 1-mm thick layer of skin is 1.05 x 104 W/m2. The temperature at the inside surface is 37°C and the tempe
    8·1 answer
  • What is not required for current to flow through a conductor
    12·1 answer
  • 5 lb of propane is contained in a closed, rigid tank initially at 80 lbf/in^2, 110 degrees Fahrenheit. Heat transfer occurs unti
    5·1 answer
  • What is this i dont understand this at all
    9·1 answer
  • How many 3-digits numbers which are greater than 300 can be formed from 6
    12·1 answer
  • A ____ is either in the pressure reducer or in the downstream side of the system to ensure that the control air pressure does no
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!