Java Program to Find greater Number between two numbers

Java Programming : This tutorial is to find out the greatest number between two numbers entered by user using command line argument.

Java Program to Find greater Number between two numbers

 /*Write a program to find greater number between two numbers entered by user.

Program code by codext.com
*/
 class GREATESTof2{

  public static void main(String args[])
  {

      //taking value as command line argument.

      //Converting String format to Integer value

      int i = Integer.parseInt(args[0]);

      int j = Integer.parseInt(args[1]);

      if(i > j)

          System.out.println(i+" is greater than "+j);

      else

          System.out.println(j+" is greater than "+i);

  }

}

Output of Java Program to Find greater Number between two numbers

Here in the screenshot, you can see that firstly we have compiled the java source code using "javac GREATESTof2.java" command after that we have run the program using "java" command and entered two numbers 45 and 67, whose value is being passed by command line argument. In next line you can see the accurate result of this java program to find greater number, as in above example 67 is greater, so in screenshot it shows 67 is greater than 45.

0 comments:

Post a Comment