Monday, 14 March 2016

To find Greatest number in java coding.

Now lets see the coding for finding the greatest number.

import java.io.*;
class Greatest
{
public static void main(String args[])throws IOException
{
int a,b,c;
DataInputStream s = new DataInputStream(System.in);
a=Integer.parseInt(s.readLine());
b=Integer.parseInt(s.readLine());
c=Integer.parseInt(s.readLine());
if((a==b) && (a==c))
 {
    System.out.println("Three numbers are same.The Greatest number is" +a);
 }
else if(a==b && a!=c)
 {
   if(b>c)
      {
         System.out.println("The Greatest number is" +b );
      }
    else
      {
         System.out.println("The Greatest number is"+c);
      }
 }
else if(b==c && b!=a)
  {
    if(b>a)
     {
        System.out.println("The Greatest number is"+b);
      }
     else
      {
        System.out.println("The Greatest number is"+a);
       }
  }
else if(a==c && a!=b)
 {
  if(a>b)
      {
       System.out.println("The Greatest number is"+a);
      }
  else
     {
       System.out.println("The Greatest number is"+b);
     }
}
else if(a>b && a>c)
 {
   System.out.println(a+"is the Greatest Number");
 }
else if(b>c && b>a)
 {
   System.out.println(b+"is the Greatest Number");
 }
else
  {
    System.out.println(c+"is the Greatest Number");

  }
}
}

Set the path and compile the program.

H:\>path=C:\jdk1.3\bin;

H:\>javac Greatest.java
Note: Greatest.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

H:\>java Greatest
25
25
25
Three numbers same.The greatest number is 25.

H:\>java Greatest
25
26
27
27is the Greatest Number