+ 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 }

7th Apr 2021, 10:48 AM
Sachin Saxena
Sachin Saxena - avatar
1 ответ
+ 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.
7th Apr 2021, 11:03 AM
Josh Greig
Josh Greig - avatar