In: Computer Science
Input from console 3 double numbers, compare these 3 numbers and display them from small to great.
In Java Please
Source Code:
Output:
Code in text format (See above images of code for indentation):
import java.util.*;
/*class definition*/
public class Main
{
/*main method*/
public static void main(String[] args)
{
/*Scanner object to read data from the user*/
Scanner read=new Scanner(System.in);
double a,b,c;
/*read 3 values from console*/
System.out.print("Enter the value of a: ");
a=read.nextDouble();
System.out.print("Enter the value of b: ");
b=read.nextDouble();
System.out.print("Enter the value of c: ");
c=read.nextDouble();
/*compare and print small to greatest*/
if(a<b&&a<c)
{
System.out.print(a+" ");
if(b<c)
{
System.out.print(b+" ");
System.out.print(c+" ");
}
else
{
System.out.print(c+" ");
System.out.print(b+" ");
}
}
/*order b a c or b c a prints*/
else if(b<a&&b<c)
{
System.out.print(b+" ");
if(a<c)
{
System.out.print(a+" ");
System.out.print(c+" ");
}
else
{
System.out.print(c+" ");
System.out.print(a+" ");
}
}
/*ordere c a b or c b a*/
else
{
System.out.print(c+" ");
if(a<b)
{
System.out.print(a+" ");
System.out.print(b+" ");
}
else
{
System.out.print(b+" ");
System.out.print(a+" ");
}
}
}
}