Computer Applications
Write a program that accepts three numbers from the user and displays them either in "Increasing Order" or in "Decreasing Order" as per the user's choice.
Choice 1: Ascending order
Choice 2: Descending order
Sample Inputs: 394, 475, 296
Choice 2
Sample Output
First number : 475
Second number: 394
Third number : 296
The numbers are in decreasing order.
Java
Java Conditional Stmts
30 Likes
Answer
import java.util.*;
public class KboatSortNumbers
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter first number: ");
int a = in.nextInt();
System.out.print("Enter second number: ");
int b = in.nextInt();
System.out.print("Enter third number: ");
int c = in.nextInt();
int max = 0, mid = 0, min = 0;
System.out.println("Choice 1: Ascending Order");
System.out.println("Choice 2: Descending Order");
System.out.print("Enter your choice: ");
int ch = in.nextInt();
if(ch != 1 && ch != 2) {
System.out.println("Wrong choice.");
}
else {
if(a>b && a>c) {
max = a;
if(b>c) {
mid = b;
min = c;
}
else {
mid = c;
min = b;
}
}
if(b>a && b>c) {
max = b;
if(a>c) {
mid = a;
min = c;
}
else {
mid = c;
min = a;
}
}
if(c>a && c>b) {
max = c;
if(a>b) {
mid = a;
min = b;
}
else {
mid = b;
min = a;
}
}
}
if(ch == 1) {
System.out.println("First number: " + min);
System.out.println("Second number: " + mid);
System.out.println("Third number: " + max);
System.out.println("The numbers are in increasing order");
}
else {
System.out.println("First number: " + max);
System.out.println("Second number: " + mid);
System.out.println("Third number: " + min);
System.out.println("The numbers are in decreasing order");
}
}
}
Variable Description Table
Program Explanation
Output


Answered By
11 Likes
Related Questions
A courier company charges differently for 'Ordinary' booking and 'Express' booking based on the weight of the parcel as per the tariff given below:
Weight of parcel Ordinary booking Express booking Up to 100 gm ₹80 ₹100 101 to 500 gm ₹150 ₹200 501 gm to 1000 gm ₹210 ₹250 More than 1000 gm ₹250 ₹300 Write a program to input weight of a parcel and type of booking (`O' for ordinary and 'E' for express). Calculate and print the charges accordingly.
Write a program to input a number and check whether it is a perfect square or not. If the number is not a perfect square then find the least number to be added to input number, so that the resulting number is a perfect square.
Example 1:
Sample Input: 2025
√2025 = 45
Sample Output: It is a perfect square.
Example 2:
Sample Input: 1950
√1950 = 44.1588……..
Least number to be added = 452 - 1950 = 2025 - 1950 = 75Write a menu driven program to calculate:
- Area of a circle = p*r2, where p = (22/7)
- Area of a square = side*side
- Area of a rectangle = length*breadth
Enter 'c' to calculate area of circle, 's' to calculate area of square and 'r' to calculate area of rectangle.
Write a program using switch case to find the volume of a cube, a sphere and a cuboid.
For an incorrect choice, an appropriate error message should be displayed.- Volume of a cube = s * s *s
- Volume of a sphere = (4/3) * π * r * r * r (π = (22/7))
- Volume of a cuboid = l*b*h