Find Out Max,Mid & Minimum Number From 3 Input Numbers using Java Program
Code:
import java.util.Scanner;
public class MaxMidMin
{
public static void main(String[] args)
{
float n1,n2,n3;
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter The Value Of 1sr Number : ");
n1 = sc.nextFloat();
System.out.print("\nEnter The Value Of 2nd Number : ");
n2 = sc.nextFloat();
System.out.print("\nEnter The Value Of 3rd Number : ");
n3 = sc.nextFloat();
if(n1>n2 && n1>n3 && n2>n3)
{
System.out.println("\nMax : "+n1+", Mid : "+n2+", Min : "+n3+"\n");
}
else if(n1>n2 && n1>n3 && n3>n2)
{
System.out.println("\nMax : "+n1+", Mid : "+n3+", Min : "+n2+"\n");
}
else if(n2>n1 && n2>n3 && n1>n3)
{
System.out.println("\nMax : "+n2+", Mid : "+n1+", Min : "+n3+"\n");
}
else if(n2>n1 && n2>n3 && n3>n1)
{
System.out.println("\nMax : "+n2+", Mid : "+n3+", Min : "+n1+"\n");
}
else if(n3>n1 && n3>n2 && n1>n2)
{
System.out.println("\nMax : "+n3+", Mid : "+n1+", Min : "+n2+"\n");
}
else if(n3>n1 && n3>n2 && n2>n1)
{
System.out.println("\nMax : "+n3+", Mid : "+n2+", Min : "+n1+"\n");
}
}
}
Output of program:
import java.util.Scanner;
public class MaxMidMin
{
public static void main(String[] args)
{
float n1,n2,n3;
Scanner sc = new Scanner(System.in);
System.out.print("\nEnter The Value Of 1sr Number : ");
n1 = sc.nextFloat();
System.out.print("\nEnter The Value Of 2nd Number : ");
n2 = sc.nextFloat();
System.out.print("\nEnter The Value Of 3rd Number : ");
n3 = sc.nextFloat();
if(n1>n2 && n1>n3 && n2>n3)
{
System.out.println("\nMax : "+n1+", Mid : "+n2+", Min : "+n3+"\n");
}
else if(n1>n2 && n1>n3 && n3>n2)
{
System.out.println("\nMax : "+n1+", Mid : "+n3+", Min : "+n2+"\n");
}
else if(n2>n1 && n2>n3 && n1>n3)
{
System.out.println("\nMax : "+n2+", Mid : "+n1+", Min : "+n3+"\n");
}
else if(n2>n1 && n2>n3 && n3>n1)
{
System.out.println("\nMax : "+n2+", Mid : "+n3+", Min : "+n1+"\n");
}
else if(n3>n1 && n3>n2 && n1>n2)
{
System.out.println("\nMax : "+n3+", Mid : "+n1+", Min : "+n2+"\n");
}
else if(n3>n1 && n3>n2 && n2>n1)
{
System.out.println("\nMax : "+n3+", Mid : "+n2+", Min : "+n1+"\n");
}
}
}
Output of program:
No comments