Sunday, October 21, 2012

Java program to find largest among 3 numbers


import java.io.*;
class largest
{
 int a,b,c,large;
 void read()throws IOException
 {
            BufferedReader br=new BufferedReader( new InputStreamReader(System.in));
            System.out.println("Enter 3 numbers");
            a=Integer.parseInt(br.readLine());
            b=Integer.parseInt(br.readLine());
            c=Integer.parseInt(br.readLine());
 }
 void check()
 {    if(a>b & a>c)
       large=a;
    else if(b>c)
       large=b;
    else 
       large=c;
   System.out.println("The largest number is "+large);
 }
 public static void main(String s[])throws IOException
 {         largest n=new largest();
            n.read();
            n.check(); }
}   

Output


0 comments:

Post a Comment