Java Program to find maximum using ladder if...else...if
/**
* Java Program to find maximum using ladder if...else...if
*/
import java.util.Scanner;
class Test
{
public static void main(String[] args)
{
int x, y, z,max=0;
Scanner p=new Scanner(System.in);
/* Input three numbers from user */
System.out.print("Enter x value:");
x=p.nextInt();
System.out.print("Enter y value:");
y=p.nextInt();
System.out.print("Enter y value:");
z=p.nextInt();
if((x > y) && (x > z))
{
/* If x is greater than both */
max = x;
}
else if((y > x) && (y > z))
{
/* If y is greater than both */
max = y;
}
else if((z > x) && (z > y))
{
/* If z is greater than both */
max = z;
}
/* Print maximum number */
System.out.println("Maximum among all three numbers = "+max);
}
}
Output:
Enter x value:30
Enter y value:80
Enter y value:40
Maximum among all three numbers = 80