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