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
Direction: List down or enumerate the type of outlets you want to install on your dream house. Also indicate the quantity (in pi
Lorico [155]

Answer:

Apartment outlet 4pcs

Explanation:

6 0
2 years ago
Before finishing and installing a shelved cabinet you just constructed, you need to check the
Greeley [361]

Answer:

Carpenter's square

Explanation:

The most common hand tool used to measure or set angles with its application extending to setting angles of roofs and rafters. Another name of a Carpenter's square is a framing square.

Other hand tools that are used to measure angles are;

  • The combination square that allows a user to set both 90°  and 45° angles
  • A Bevel that allows users to set any angle they like.
  • A Protractor that resembles a bevel but its marks are marked in an arc.
  • An electromagnetic angle finder which gives a reading according to the measure of the arms adjusted by the user.
7 0
3 years ago
Dust, dirt, or metal chips can pose a potential ____ injury risk in a shop.
Liono4ka [1.6K]

Answer: Eye injury

Explanation: small material such as dust, dirt, and metal shards can harm your eyes with potential blindness or infection.

7 0
2 years ago
What is one thing a person should do to stay safe when exercising
elixir [45]
Staying hydrated at all times
7 0
3 years ago
Read 2 more answers
What. is the capital city of panjab​
kotegsom [21]

Answer:

Chandigarh

Explanation:

Chandigarh city is the capital of the territory and of the states of Haryana and Punjab. Chandigarh's name, meaning “stronghold of the goddess Chandi,” is derived from the Chandi Mandir, a temple dedicated to the goddess that is located near the town of Mani Majra. Area union territory, 44 square miles (114 square km).

8 0
3 years ago
Other questions:
  • A team member who has been a good worker for many years has recently been doing poor work. You suspect that he may be tired of h
    6·1 answer
  • (a) Design a first-order passive high-pass filter with a cutoff frequency of 1000 rad/sec.
    8·1 answer
  • Wiring harnesses run
    12·1 answer
  • Explain what a margin of safety is in driving as well as how it can help minimize risk.
    14·1 answer
  • Can some one help me with this plumbing question. Even just a guess.<br> Plz no shady links
    11·2 answers
  • A beam has been fixed to the floor by the pin at B and the roller at A as shown in figure 1 below.​
    7·1 answer
  • What do you think of web 3.0? do you think it will be realized someday in the future?​
    5·1 answer
  • A parallel circuit has a resistance of 280 and an inductive reactance of 360 02. What's this circuit's impedance?
    6·1 answer
  • Determine the initial void ratio, the relative density and the unit weight (in pounds per cubic foot) of the specimens for each
    6·1 answer
  • The complete stress distribution obtained by superposing the stresses produced by an axial force and a bending moment is correct
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!