- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
Conditional Constructs in Java
Chapter 8
Conditional Constructs in Java
Class 10 - Logix Kips ICSE Computer Applications with BlueJ
![]() Share with a Friend |
Java Program: Display Three Numbers in Descending Order
20. Write a program in Java to read three integers and display them in descending order.
import java.util.Scanner;
public class DescendingOrder {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Input three numbers
System.out.print("Enter first number: ");
int a = sc.nextInt();
System.out.print("Enter second number: ");
int b = sc.nextInt();
System.out.print("Enter third number: ");
int c = sc.nextInt();
// Sorting in descending order using comparisons
int largest, middle, smallest;
if (a >= b && a >= c) {
largest = a;
if (b >= c) {
middle = b;
smallest = c;
} else {
middle = c;
smallest = b;
}
} else if (b >= a && b >= c) {
largest = b;
if (a >= c) {
middle = a;
smallest = c;
} else {
middle = c;
smallest = a;
}
} else {
largest = c;
if (a >= b) {
middle = a;
smallest = b;
} else {
middle = b;
smallest = a;
}
}
// Output
System.out.println("Numbers in descending order:");
System.out.println(largest + " " + middle + " " + smallest);
sc.close();
}
}
Output
Sample Input Enter first number: 45 Enter second number: 12 Enter third number: 78 Sample Output Numbers in descending order: 78 45 12
Explanation
- The program reads three integers using the Scanner class.
- Conditional statements (if-else) are used to:
- Find the largest, middle, and smallest numbers.
- The numbers are then printed in descending order (largest → smallest).
