How to find the Max, Min and Middle of 3 numbers?

Hi everybody, in this program we shall find the max, min and middle of 3 numbers to be input through the Scanner.

The 3 variables are named a,b and c.

We are using a nested loop system for finding the max and the min. The mid element is being found by subtracting the min and max from the total.


import java.util.Scanner;

public class ThreeMax {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter Three Numbers to find out Max Min and Middle");
int a=s.nextInt();
int b=s.nextInt();
int c=s.nextInt();
if (a>=b)
if (a>=c)
System.out.println(a);
else
System.out.println(c);
else
if(b>=c)
System.out.println(b);
else
System.out.println(c);

}

}

Output

Leave a Reply