Java Program to find minimum using ladder if...else...if
/**
* Java Program to find minimum using ladder if...else...if
*/
import java.util.Scanner;
class Test
{
public static void main(String[] args)
{
int x, y, z,min=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 smaller than both */
min = x;
}
else if((y < x) && (y < z))
{
/* If y is smaller than both */
min = y;
}
else if((z < x) && (z < y))
{
/* If z is smaller than both */
min = z;
}
/* Print maximum number */
System.out.println("Minimum among all three numbers = "+min);
}
}
Output:
Enter x value:20
Enter y value:10
Enter y value:80
Minimum among all three numbers = 10