
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Ask the user to enter three numbers. Prints the three numbers in order.
*USING ONLY IF/ELSE IF STATEMENTS
![### Java Program to Order Three Numbers
Here is a Java program that takes three integers as input and prints them in ascending order.
#### Code Breakdown
```java
import java.util.Scanner;
public class InOrderThree
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter three numbers: ");
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
// Complete the program
if ( a < b && a < c && b < c) {
System.out.print("Ordered: " + a + b + c);
}
else if (a < b && a < c && c < b) {
System.out.print("Ordered: " + a + c + b);
}
else if (b < a && b < c && a < c) {
System.out.print("Ordered: " + b + a + c);
}
else if(b < a && b < c && c < a) {
System.out.print("Ordered: " + b + c + a);
}
else if (c < a && c < b && a < b) {
System.out.print("Ordered: " + c + a + b);
}
else {
System.out.print("Ordered: " + c + b + a);
}
}
}
```
### Explanation
1. **Import Statement**:
- `import java.util.Scanner;`: This statement imports the `Scanner` class, which is used to get user input.
2. **Class Declaration**:
- `public class InOrderThree`: Declares a public class named `InOrderThree`.
3. **Main Method**:
- `public static void main(String[] args)`: This is the entry point of the program where the execution starts.
4. **Scanner Initialization**:
- `Scanner in = new Scanner(System.in);`: Creates a `Scanner` object to take input from the user.
5. **User Input**:
- `System.out.print("Please enter three numbers: ");`: Prompts the user to enter three integers.
- `int a = in.nextInt();`, `int b = in.nextInt();`, `int c = in.nextInt();`: Reads integer inputs from the user and stores them in variables `a`,](https://content.bartleby.com/qna-images/question/d772767f-fd91-4ca5-b737-b5766e3fef0a/c4f9cef8-0500-40dc-af86-fd0506eb04fb/e6g563q_thumbnail.png)
Transcribed Image Text:### Java Program to Order Three Numbers
Here is a Java program that takes three integers as input and prints them in ascending order.
#### Code Breakdown
```java
import java.util.Scanner;
public class InOrderThree
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter three numbers: ");
int a = in.nextInt();
int b = in.nextInt();
int c = in.nextInt();
// Complete the program
if ( a < b && a < c && b < c) {
System.out.print("Ordered: " + a + b + c);
}
else if (a < b && a < c && c < b) {
System.out.print("Ordered: " + a + c + b);
}
else if (b < a && b < c && a < c) {
System.out.print("Ordered: " + b + a + c);
}
else if(b < a && b < c && c < a) {
System.out.print("Ordered: " + b + c + a);
}
else if (c < a && c < b && a < b) {
System.out.print("Ordered: " + c + a + b);
}
else {
System.out.print("Ordered: " + c + b + a);
}
}
}
```
### Explanation
1. **Import Statement**:
- `import java.util.Scanner;`: This statement imports the `Scanner` class, which is used to get user input.
2. **Class Declaration**:
- `public class InOrderThree`: Declares a public class named `InOrderThree`.
3. **Main Method**:
- `public static void main(String[] args)`: This is the entry point of the program where the execution starts.
4. **Scanner Initialization**:
- `Scanner in = new Scanner(System.in);`: Creates a `Scanner` object to take input from the user.
5. **User Input**:
- `System.out.print("Please enter three numbers: ");`: Prompts the user to enter three integers.
- `int a = in.nextInt();`, `int b = in.nextInt();`, `int c = in.nextInt();`: Reads integer inputs from the user and stores them in variables `a`,
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- BOOLEAN EXPRESSION.( NEED ONLY HANDWRITTEN SOLUTION PLEASE OTHERWISE DOWNVOTE).arrow_forwardIf you want to execute one set of statements when a condition evaluates to a truthy value and another set of statements when the condition evaluates to a falsy value, you need the statement. Select one: a.while b.do/while C. switch d.if/elsearrow_forwardIf else 2arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education