Three Idiots

  Three Idiots

Create a program that reads three integers from the user and displays them in sorted order (from smallest to largest).


Use the min and max functions to find the smallest and largest values. The middle value can be found by computing the sum of all three values, and then subtracting the minimum value and


the maximum value.

Logic Test Case 1


Input (stdin)

25


12


1988


Expected Output


The minimum value is 12


The maximum value is 1988


The middle value is 25

Logic Test Case 2


Input (stdin)

9


19


1972


Expected Output


The minimum value is 9


The maximum value is 1972


The middle value is 19








Code Area

import java.util.Scanner;

import java.io.*;

public class TestClass {

public static void main(String[] args)

     { 

Scanner in=new Scanner(System.in);

       int a=in.nextInt();

       int b=in.nextInt();

       int c=in.nextInt();

       int d,e,f;

       if(a<b&&a<c)

       {

         System.out.println("The minimum value is "+a);

         d=a;

       }

       else if(b<c)

       {

         System.out.println("The minimum value is "+b);

       d=b;

       }

       else

       {

         System.out.println("The minimum value is "+c);

       d=c;

       }

       if(a>b&&a>c)

       {

         System.out.println("The maximum value is "+a);

       e=a;

       }

       else if(b>c)

       {

         System.out.println("The maximum value is "+b);

       e=b;

       }

       else

       {

         System.out.println("The maximum value is "+c);

       e=c;

       }

       if ((a < b && b < c) || (c < b && b < a)) 

       System.out.println("The middle value is "+b);  

    else if ((b < a && a < c) || (c < a && a < b)) 

       System.out.println("The middle value is "+a);  

    else

        System.out.println("The middle value is "+c);

         

}

}

Post a comment

0 Comments