Sunday, 16 September 2012

How to compare three numbers in Java


import java.io.*;

public class q6
{
          public static void main(String args[]) throws Exception
          {
                   InputStreamReader in = new InputStreamReader(System.in);
                  
BufferedReader br = new BufferedReader(in);
                  
System.out.print("Enter first number : ");
                  
int n1=Integer.parseInt(br.readLine());
                  
System.out.print("Enter second number : ");
                  
int n2=Integer.parseInt(br.readLine());
                  
System.out.print("Enter third number : ");
                  
int n3=Integer.parseInt(br.readLine());
                  
                        System.out.println("\n");
                  
                        if((n1>n2) && (n1>n3))
                  
                             System.out.println("First number is greatest");
                  
else if((n2>n1) && (n2>n3))
                  
                             System.out.println("second number is greatest");
                  
else
                  
                             System.out.println("third number is greatest");
          }
}

No comments:

Post a Comment