1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

this pranav(student)

Discussion in 'Java' started by pranavav08, Jun 24, 2010.

  1. pranavav08

    pranavav08 New Member

    Joined:
    Jun 24, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Jun 24, 2010
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Moved to Java Forums
     
  3. virxen

    virxen New Member

    Joined:
    Nov 24, 2009
    Messages:
    387
    Likes Received:
    90
    Trophy Points:
    0

Share This Page