Hi Friendz,

I just written a program which Accept two nos. and an operator on command line and print the result.

Here is the code -

class CmdOperator
{
public static void main(String[] a)
{
int num1,num2,res;
String opr;

if (a.length > 0)
{
num1 = Integer.parseInt(a[0]);
num2 = Integer.parseInt(a[1]);
opr = a[2];
if(opr.equals("+"))
{
System.out.println("num1 + num2 = " + (num1+num2));
}
else if(opr.equals("-"))
{
System.out.println("num1 - num2 = " + (num1-num2));
}
else if(opr.equals("*"))
{
System.out.println("num1 * num2 = " + (num1*num2));
}
else if(opr.equals("/"))
{
System.out.println("num1 / num2 = " + (num1/num2));
}
else
System.out.println("Enter Proper Operator!");
}
else
{
System.out.println("Please Enter Numbers");
}
}
}


------

here are the code output -

output 1
C:\>java CmdOperator 6 2 +
num1 + num2 = 8

output 1
C:\>java CmdOperator 6 2 -
num1 + num2 = 4

output 1
C:\>java CmdOperator 6 2 /
num1 + num2 = 3

output 1
C:\>java CmdOperator 6 2 *
Enter Proper Operator!

The Question is Why it is not understanding the "*" operator?