数组无法正常工作

时间:2015-06-05 22:21:43

标签: arrays

我正在尝试在一个名为browxy.com的网站上用java创建一个科学计算器(并且它处于测试阶段,它可能只是一个bug),但当我尝试使用数组进行数字和操作时方程式,它给了我错误,说我错过了a和a;在第15行,a]和a;在第21行,a]和a;在第27行,a]和a;在第33行。任何帮助?

编辑:(另外:我还没有完成。)

import java.util.Scanner;
public class ScientificCalculator {
public static void main(String[] args) {
    System.out.println("Enter an equation.(No spaces)");
    Scanner raw = new Scanner(System.in);
    String input = raw.nextLine();
    char[] op;
    int opNumDefineCounter = 0;
    int[] nums;
    int numDefineLocation = 0;
    for (int i; i > input.length; i = i + 1) {
        if (input.substring(i, i+1).equals("+")) {
            op[opNumDefineCounter] = "+";
            opNumDefineCounter = opNumDefineCounter + 1;
            int[opNumDefineCounter] = Integer.parseInt(input.substring(numDefineLocation, i));
            numDefineLocation = i+1;
        }
        else if (input.substring(i, i+1).equals("-")) {
            op[opNumDefineCounter] = "-";
            opNumDefineCounter = opNumDefineCounter + 1;
            int[opNumDefineCounter] = Integer.parseInt(input.substring(numDefineLocation, i));
            numDefineLocation = i+1;
        }
        else if (input.substring(i, i+1).equals("/")) {
            op[opNumDefineCounter] = "/";
            opNumDefineCounter = opNumDefineCounter + 1;
            int[opNumDefineCounter] = Integer.parseInt(input.substring(numDefineLocation, i));
            numDefineLocation = i+1;
        }
        else if (input.substring(i, i+1).equals("*")) {
            op[opNumDefineCounter] = "*";
            opNumDefineCounter = opNumDefineCounter + 1;
            int[opNumDefineCounter] = Integer.parseInt(input.substring(numDefineLocation, i));
            numDefineLocation = i+1;
        }
        else {
            //nothing happens
        }
    }

}

}

1 个答案:

答案 0 :(得分:1)

我不是Java专家,但这看起来不对:

int[opNumDefineCounter]

int当然是数据类型,因此是保留字。但是,在与错误消息对应的行上使用上面四次的表达式。我很确定你打算使用变量nums,如下所示:

nums[opNumDefineCounter]