Friday, August 26, 2011

Find out minimum number in java


//Find out Minimum number from the given three input.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MinNumber
{
public static void main(String args[]) throws IOException
{
String s1,s2,s3;
int n1,n2,n3;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

//Get first number
System.out.print("Enter first number =");
s1 = br.readLine();
n1 = Integer.valueOf(s1).intValue();

//Get second number
System.out.print("Enter first number =");
s2 = br.readLine();
n2 = Integer.valueOf(s2).intValue();

//Get third number
System.out.print("Enter first number =");
s3 = br.readLine();
n3 = Integer.valueOf(s3).intValue();

//Logic to find out Minimum number.
if(n1 {
if(n1 System.out.println("Minimum number = "+n1);
else
System.out.println("Minimum number = "+n3);
}
else
{
if(n2 System.out.println("Minimum number = "+n2);
else
System.out.println("Minimum number = "+n3);
}
}
}


Output=>

Enter first number =25
Enter first number =36
Enter first number =9
Minimum number = 9

No comments:

Post a Comment