why the first code report the desired result and the second not (Java beginner)
public class p1 {
public static void main(String[] args) throws IOException{
int[] a = new int[100];
int i = 0 ;
for(int element1 : a){
element1 = i++;
System.out.println(element1);
}
}
}
result 0,1,2,3,......,99 second version:-
public class p1 {
public static void main(String[] args) throws IOException{
int[] a = new int[100];
int i = 0 ;
for(int element1 : a){
element1 = i++;
}
for(int element2 : a){
System.out.println(element2);
}
}
} result 0,0,0,0,.....,0