Java Program to Find Greatest of Two Number

Java program to find greatest among any two numbers. User enter any two number and press enter button to show the result this number is greatest number.
import java.util.*;
class Greatest
{
 public static void main(String args[])
 {
  int a,b;
  Scanner rd = new Scanner(System.in);
  System.out.print("Enter two numbers:");
  a = rd.nextInt();
  b = rd.nextInt();
  if(a>b)
   {
    System.out.println( a+" "+"is the greatest no.");
   }
  else
   {
    System.out.println(b+" "+"is the greatest no.");
   }
 }
}

Output

Enter two numbers : 15 40
40 is the greatest no.

Post a Comment

0 Comments