Powered by Blogger.

A Basic java program for finding maximum of two numbers and min

class Maxoftwo{
  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:

javac Maxoftwo.java
java Maxoftwo 10 20
    20 is greater then 10

//end 

/* we can also write minimum of two nos program using conditional operator */ 


//Find Minimum of 2 nos. using conditional operator

class Minoftwo{
      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]);
      int result = (i
      System.out.println(result+" is a minimum value");
  }
}
 
Share on Google Plus

About rajasekhar reddy

Author is a Tech savvy and Web Enthusiast by nature and really love to help users by providing how-to posts and tech tutorials. He is a founder and author of technolamp.co.in and programming9.com. YouTube Channel to SUBSCRIBE:
    https://www.youtube.com/user/nvrajasekhar
Available: info@programming9.com
Post a Comment