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

  }

}

 

0 komentar:

Post a Comment

Related Posts with Thumbnails
GiF Pictures, Images and Photos