0
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 }
2 ответов
+ 3
marks[i] would mean marks[10] which dosent exist and is out of bounds.
Your looking for System.out.println(i)
Each loop "i" holds one elememt of the array
+ 1
System.out.println(i) is enough. marks[i] means you try to get 10th,20th... element. But there no such elements. So the error occur.
Delete duplicate question
https://www.sololearn.com/discuss/2748560/?ref=app