java - 为什么while这里会被判定为unexpected token啊
怪我咯
怪我咯 2017-04-17 17:53:41
0
6
922
class list{
    int i = 0;
    while(i>=0){
    i++;
} 
}
public class Fb {
    public static void main(String args[]){
    }
}

刚开始写。。。就报错了,以前没遇到过的错误。
错误是while为unexpected token

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(6)
迷茫

I believe the poster wrote the code in an IDE, such as eclipse.
This is a compilation error, because the code is not standardized, and because the IDE will check the syntax of the code when you write it. So you will get the unexpected token error.
Only methods and variables can be defined under class. But you cannot write logic code directly. You should define these codes in a method, such as

class FB {
    public void list() {
         int i = 0;
         while(i>=0){
             i++;
         }
    }
}

In addition, this code is actually problematic because it is an infinite loop.

左手右手慢动作

I don’t know what you want to do. Anyway, your code is indeed wrong. You actually wrote the statement in class,
class list {

int i = 0;
public list() {
    while ( i >= 0 ) {
        i++;
    }
}

}

阿神

There should be a function in the class, and then write a while statement inside it
Are you sure you have read the Java syntax once?

阿神

class list{
public void test(){

int i = 0;
while(i>=0){
i++;
}

}
}

小葫芦

What language is this?

巴扎黑

You have a grammatical error and the compilation will not pass.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template