Saturday, 3 January 2015

Java program to arithmatic operations(input from command line)

package com.srk.core;
/**
 * @author skummitha
 *
 */
public class CmdArgs2 {
       public static void main(String args[]) {
             int a = Integer.parseInt(args[0]);
             int b = Integer.parseInt(args[1]);
             System.out.println("Addition :" + (a + b));
             System.out.println("subtraction :" + (a - b));
             System.out.println("Multiplication :" + (a * b));
             try {
                    System.out.println("Division :" + (a / b));
             } catch (Exception e) {
                    System.out.println(e);
                    System.err.println("cant divide");
             }
             System.out.println("finished");
       }

}

No comments:

Post a Comment