first paragraph code:
public class HelloWorld {
public static void main(String[] args) {
int i = 0; //i
for(int i = 0 ; i < 10 ; iPP) { // i
System.out.println(i);
}
}
}
the first piece of code has two I, one outside for and one inside for. The system prompts for naming conflicts
second paragraph code:
public class HelloWorld {
public static void main(String[] args) {
for(int i = 0; i < 10 ; iPP) {
System.out.println(i);
}
for(int i = 0; i < 10 ; iPP) {
System.out.println(i);
}
}
}
The second piece of code has two juxtaposed for loops, each with a variable I, but the two do not collide with names.
I have two questions:
which of the two I is a local variable and which is a global variable in the first, first and second sections of code?
second, why the first code I name conflict, the second code I name conflict?