[JAVA rookie] ask questions about variable naming conflicts. Two I, one inside the for loop and one outside the for loop.

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?

Jul.18,2022

this problem is the scope of variables

in the first code int I = 0; is in the entire main function, while the for loop is in the main function, so the system prompts for naming conflicts.

the scope of the two I in the second paragraph of code is in two for loops, so there is no conflict;

    public class HelloWorld {
    
        int hello=0; //
        
        
        
        public static void main(String[] args) {
        
            int j = 0;      //main
            
            for(int i = 0 ; i < 10 ; iPP) {   // for
            
                System.out.println(i);
                
            }
        }
    }
   
Menu