Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   this pranav(student) (http://www.go4expert.com/forums/this-pranav-student-t22515/)

pranavav08 24Jun2010 10:58

this pranav(student)
 
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

shabbir 24Jun2010 11:18

Re: this pranav(student)
 
Moved to Java Forums

virxen 26Jun2010 03:31

Re: this pranav(student)
 
http://bugs.sun.com/bugdatabase/view...bug_id=4672990


All times are GMT +5.5. The time now is 21:18.