Syntax error on tokens [duplicate]

三世轮回 提交于 2019-11-27 15:58:21

The statement precedence.put("+", 2); has to be within a method or a block.

For example, you can place it within the constructor

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

Not related to the problem you have, classes need to start with a capital letter, according to the Java Naming Conventions

gaurav5430
precedence.put("+", 2); <=========== This is where the error occurs

this statement is not inside any block , hence it is not permitted.

remove it from here and put it inside any other method or block

Note: this is how java works.

for an extended discussion, please refer to:

Why can't I do assignment outside a method?

precedence.put("+", 2);

The above line is incorrectly placed. You should initialise the Hashtable in constructor.

Statements should be placed in inside constructors/methods/blocks, otherwise Compile time error occurs.

precedence.put("+", 2); <=========== This is where the error occurs

Move that line to constructor/method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!