Why does think not work? It just prints zeros. However it works when I use a normal for loop with an index value 'i' and using 'a[i]' inside the body of the loop.
The problem is not with the printing loop, as it does not print the values, even with a normal for loop.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int[] a = new int[5];
for (int i : a)
{
System.out.println("Enter number : ");
i=s.nextInt();
}
System.out.println("\nThe numbers you entered are : \n");
for (int i : a)
{
System.out.println(i);
}
}
}