Friday, August 26, 2011

Find out maximum number in java


//Find out Maximum number between three input number.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MaxNumber
{
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 Maximum number.
if(n1>n2)
{
if(n1>n3)
System.out.println("Maximum number = "+n1);
else
System.out.println("Maximum number = "+n3);
}
else
{
if(n2>n3)
System.out.println("Maximum number = "+n2);
else
System.out.println("Maximum number = "+n3);
}
}
}


Output=>
Enter first number =25
Enter first number =69
Enter first number =5
Maximum number = 69

No comments:

Post a Comment