Welcome to Home.

Monday, August 6, 2018

FIND MAXIMUM BETWEEN 2 NUMBERS | JAVA


Finding Maximum number between 2 number is quite quite quite easy in any Programming Language. We just have to use comparison operator (<,>,<=,>=,==). In  this case we gonna make use of > operator.

//Find Maximum of 2 nos.


class Maxof2{

  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);

        // If you have one statement inside if or else then there is no required of braces

      else

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

  }

}


If you want comparison between 3 to 4 numbers write comment in below section.

No comments:

Post a Comment