Wap to accept three different single digit numbers between 1 and 9 (both inclusive). Display the greatest the greatest and smallest three digit number.

//Wap to accept three different single digit numbers between 1 and 9 (both inclusive).
//Display the greatest the greatest and smallest three digit number.
/* input = 2,7,4
 * output = Greatest three digit number =742
 * Smallest three digit number = 247
 */
import java.util.*;
class number
{
    public static void main(String[]args)
    {
        Scanner sc=new Scanner(System.in);
        int a,b,c,gn=0,sn=0;
        System.out.println("enter the first number between 1 and 9:");
        a=sc.nextInt();
        System.out.println("enter the second number between 1 and 9:");
        b=sc.nextInt();
        System.out.println("enter the third number between 1 and 9:");
        c=sc.nextInt();
        if((a>b)&&(a>c))
        {
            if(b>c)
            {
                gn=100*a+10*b+c;
                sn=100*c+10*b+a;
            }
            else
            {
                gn=100*a+10*c+b;
                sn=100*b+10*c+a;
            }
        }
        if((b>a)&&(b>c))
        {
            if(a>c)
            {
                gn=100*b+10*a+c;
                sn=100*c+10*a+b;
            }
            else
            {
                gn=100*b+10*c+a;
                sn=100*a+10*c+b;
            }
        }
        if((c>a)&&(c>b))
        {
            if(a>b)
            {
                gn=100*c+10*a+b;
                sn=100*b+10*a+c;
            }
            else
            {
                gn=100*c+10*b+a;
                sn=100*a+10*b+c;
            }
        }
        System.out.println("Greatest three digit number:"+gn);
        System.out.println("Smallest three digit number:"+sn);
    }
}
               

OUTPUT

enter the first number between 1 and 9:
5
enter the second number between 1 and 9:
7
enter the third number between 1 and 9:
4
Greatest three digit number:754
Smallest three digit number:457

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...