与令牌语法有关的未知错误 [英] Unknown error relating to syntax of tokens

查看:163
本文介绍了与令牌语法有关的未知错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法解决Java中以下代码的错误:

I can't work out what is wrong with the following code in Java:

import java.util.*;

public class stringCalculator {
    String operator_array[] = {"+", "-", "/", "*", "(", ")"};
    Queue<Integer> outputQueue = new LinkedList<Integer>();
    Stack <Object> operatorStack = new Stack<Object>();
    Hashtable<String, String> operatorPrecedence = new Hashtable<String, String>();
    operatorPrecedence.put("+", "2");

我收到以下错误:

令牌上的语法错误,删除这些令牌,这与以下行有关:

Syntax error on tokens, delete these tokens, This is in relation to the following line:

operatorPrecedence.put("+", "2");

感谢任何帮助

推荐答案

您不能将语句直接放在课堂内。

You can not put statements directly inside a class.

创建一个方法或构造函数,并将调用放在在那里。

Create a method or a constructor and put the call to put there.

public stringCalculator() {
    operatorPrecedence.put("+", "2");
}

此外,使用大写名称是很好的做法,如 StringCalculator

Also, it is good practice to use an upper-case name for the class, like StringCalculator.

这篇关于与令牌语法有关的未知错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆