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
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
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
Correct answer upstairs,