Error: ‘)’ expected compiler error

I cannot seem to figure out why i am getting this error

Math.java:6: error: ')' expected
        if(args[1].equalsIgnoreCase("+")
                                        ^
Math.java:11: error: ')' expected
                else if(args[1].equalsIgnoreCase("x")
                                                     ^
Math.java:16: error: ')' expected
                else if(args[1].equalsIgnoreCase("-")
                                                     ^
Math.java:21: error: ')' expected
                else if(args[1].equalsIgnoreCase("/")
                                                     ^
4 errors

My code is

  class Math 
{
    public static void main(String args[])
    {
        if(args[1].equalsIgnoreCase("+")
        {
        sum = Integer.parseInt(args[0]) + Integer.parseInt(args[2]);
        System.out.println("The answere is : " + sum);
        }
        else if(args[1].equalsIgnoreCase("x")
        {
        sum = Integer.parseInt(args[0]) * Integer.parseInt(args[2]);
        System.out.println("The answere is : " + sum);
        }
        else if(args[1].equalsIgnoreCase("-")
        {
        sum = Integer.parseInt(args[0]) - Integer.parseInt(args[2]);
        System.out.println("The answere is : " + sum);
        }
        else if(args[1].equalsIgnoreCase("/")
        {
        sum = Integer.parseInt(args[0]) / Integer.parseInt(args[2]);
        System.out.println("The answere is : " + sum);
        }
        else
        {
        System.out.println("Something seems to be wrong, please try again.");
        }

    }
}

When i try to enter the closing parenthesizes where it says they should go, it get more errors. Can anyone give me a brief description of what causes this error. I am simply trying to make a program that with do math, based on arguments entered into the command line when the program is run.

For example if i entered “java Math 1 + 1” It would solve that problem and spit out “The answere is 2.”

Any help you guys can offer on this would be greatly appreciated.

Leave a Comment