Pages

Simple calculator value & operator pass by command prompt


import java.util.*;
   class cals

   {
    public static void main(String args[])
       { 
           Scanner sc= new Scanner(System.in);
        
           
          
           int a =Integer.parseInt(args[0]);
           int b =Integer.parseInt(args[1]);
          if (args[2].equals("+"))
          {
          System.out.println("Sum of two integer is =  "+(a + b));
         }
          if (args[2].equals("-"))
          {
          System.out.println("Minus of two integer is =  "+(a - b));
          }
          if (args[2].equals("*"))
          {
          System.out.println("Multiple of two integer is =  "+(a*b));
          }
          if (args[2].equals("/"))
          {
          System.out.println("Divison of two integer is =  "+(a / b));
          }
  
    }
 }


Output::


   java cals 2 5 +  7

No comments:

Post a Comment