java - 麻烦老师看下这段代码有哪些错误,无法运行。
巴扎黑
巴扎黑 2017-04-18 10:39:04
0
3
305
巴扎黑
巴扎黑

reply all(3)
左手右手慢动作

Compile in the compilation environment based on the code you provide

That is, x is defined repeatedly. A variable can only be defined once in the same scope (here refers to the main() method). The above code defines x in both "int x=13;" and "for (int x=0;x<10;x=x+1)", so an error occurs.

I guess the questioner wants to print the value of x, so remove the "int" keyword in the for loop

class Demo{
    public static void main(String[] args) {       
        int x=13;
        while ( x >12){ 
            x=x-1;
        }
        for (x=0;x<10;x=x+1){
            System.out.print("x is now "+ x);
        }
    }
}

If you still don’t understand the question, you can refer to this blog post

阿神

int x=13; defines a variable x
int x=0 and defines another variable x
repeated definition

PHPzhong

Correct answer upstairs,

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