this pranav(student)

pranavav08's Avatar, Join Date: Jun 2010
Newbie Member
wrote a java to read integer Command line argument program which would perform some opertions as follows:
Code:
import java.lang.Math;
class ComLineNum 
{
    public static void main(String[] args) 
    {
        int result=0,firstArg=0,secArg=0;
        char operArg='\0';
        try
        {
            firstArg = Integer.parseInt(args[0]);
            operArg = args[1].charAt(0);
            secArg=Integer.parseInt(args[2]);            
        }
        catch (Exception e){}
        switch(operArg)
        {
            case '+' : result =firstArg + secArg;
                       break;
            case '-' : result =firstArg - secArg;
                       break;
            case '*' : result =(firstArg * secArg);
                       break;
            case '/' : result =firstArg / secArg;
                       break;
            case '%' : result =firstArg % secArg;
                       break;
            case '^' : result =(int)Math.pow(firstArg ,secArg);
                       break;
            default:   System.out.println ("Default");
                       break;
        }
        System.out.println(result);
    }
}
The output is:
F:\JAVA>java ComLineNum 23 + 3
26

But the problem is for the following input:

F:\JAVA>java ComLineNum 23 * 3
Default
0

please hell

Last edited by shabbir; 24Jun2010 at 11:17.. Reason: Code blocks
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved to Java Forums