GTU OOP Program - 5
5). Write a program that prompts the user to enter three integers and display the integers in decreasing order.
import java.util.Scanner; class Program_05 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter First number : "); int num1 = input.nextInt(); System.out.print("Enter Second number : "); int num2 = input.nextInt(); System.out.print("Enter Third number : "); int num3 = input.nextInt(); int temp; if (num1 < num2 || num1 < num3) { if (num1 < num2) { temp = num1; num1 = num2; num2 = temp; } if (num1 < num3) { temp = num3; num3 = num1; num1 = temp; } } if (num2 < num3) { temp = num2; num2 = num3; num3 = temp; } System.out.print("Numbers in descending Order are : "); System.out.print(num1 + " " + num2 + " " + num3); } }
Output
Comments