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]
4 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]4 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]4 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
You’ve experienced convection cooling if you’ve ever extended your hand out the window of a moving vehicle or into a flowing wat
Anna35 [415]

Answer:

Condition A

Heat flux is 1400 W/M^2

Condition B

Heat flux is 12800 w/m^2

Explanation:

Given that:

T_s is given as  30 degree celcius

condition A

Air temperature =  - 5 degree c

convection coefficient h = 40 w/m^2. k

heat\ flux = \frac{Q}{a}= h\Delta = 40{30 - (-5)} = 1400 w/m^2

condition A

water temperature  = 10 degree c

convection coefficient = 800 w/m^2.k

heat\ flux = \frac{Q}{A} = H(\Delta} = 800\times (30-14) = 12800w/m^2

7 0
3 years ago
Describe with an example how corroded structures can lead to environment pollution? ​
raketka [301]
According to EonCoat, corrosion is the process of decay on a material caused by a chemical reaction with its environment. Corrosion of metal occurs when an exposed surface comes in contact with a gas or liquid, and the process is accelerated by exposure to warm temperature, acids, and salts.” (1)
Although the word ‘corrosion’ is used to describe the decay of metals, all natural and man-made materials are subject to decay, and the level of pollutants in the air can speed up this process.
5 0
3 years ago
As described in "A Note About Bacterial Reproduction -- and the "Culture Bias,"" the organism Epulopisciumdoes not divide by bin
zloy xaker [14]

Answer:

A

Explanation:

The best method that will yield significantly more accurate result is to use spectrophotometer to read the turbidity of the sample and increase in turbidity is associated with increase biomass.

5 0
3 years ago
Which one of the following activities is not an example of incident coordination
Lady bird [3.3K]
Directing, ordering, or controlling
7 0
4 years ago
Ma poate ajuta cineva?
kari74 [83]
Da, sigur. cu ce ai nevoie de ajutor?
5 0
3 years ago
Other questions:
  • The y-component of velocity for a certain 2-D flow field is given as u = 3xy + x2 . Determine the x-component of velocity if the
    12·1 answer
  • Technician A says that the first step in diagnosing engine condition is to perform a thorough visual inspection. Technician B sa
    8·1 answer
  • A well penetrates an unconfined aquifer. Prior to pumping, the water level (head) is 25 meters. After a long period of pumping a
    14·1 answer
  • When will the entropy value of the universe attained its maximum value?
    13·1 answer
  • Resistors of 150 Ω and 100 Ω are connected in parallel. What is their equivalent resistance?
    13·1 answer
  • . An ideal vapor compression refrigeration cycle operates with a condenser pressure of 900 kPa. The temperature at the inlet to
    14·1 answer
  • How does a belt operated supercharger work? (Not a turbo charger)
    12·1 answer
  • Which cod is the best whoever has the best awnser gets brainliest​
    12·1 answer
  • Why is there an Engineering Process?
    15·2 answers
  • The ______ number of a flow is defined as the ratio of the speed of flow to the speed of sound in the flowing fluid.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!