I am trying to give command line argument to this program. But it gives Invalid operator when operator is * e.g. 2 3 *
import java.io.*;
import java.util.*;
public class Operation{
public static void main(String args[]){
int num1, num2, res=0;
try{
Exception ex = new Exception();
if(args.length < 3)
throw(ex);
}catch (Exception e){
System.out.println("Illegal no. of arguments");
System.exit(0);
}
try{
Exception ex1 = new Exception();
num1 = Integer.parseInt(args[0]);
num2 = Integer.parseInt(args[1]);
if(args[2].equals("+"))
res = num1 + num2;
else if(args[2].equals("-"))
res = num1 - num2;
else if(args[2].equals("*"))
res = num1 * num2;
else if(args[2].equals("/"))
res = num1 / num2;
else
throw(ex1);
}catch (Exception e){
System.out.println("Invalid Operator");
System.exit(0);
}
try{
Exception ex2 = new Exception();
if(res < 0)
throw(ex2);
else
System.out.println("Result = " + res);
}catch (Exception e){
System.out.println("Result is negative");
}
}
}