+ 1
Loop vs Enhanced Loop in JAVA
i tried to print by using enhanced loop but its show outbounding exception error int marks[] ={10,20,30,40,50}; for(int i : marks) { System.out.println(marks[i])l }
1 Answer
+ 4
This is what you want instead:
int marks[] ={10,20,30,40,50};
for(int i : marks)
{
System.out.println(i);
}
The loop gives the values from the marks array to i. i is not an array index.