+ 3
Why I'm having a Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5 at For.main(For.java:10)
public class For { public static void main(String[] args) { String [] days = {"Monday", "Tuesday", "Wednesday","Thursday","Friday"}; for (int i = 0; i <= days.length; i++) { System.out.println(days[i]); } } }
6 Answers
+ 4
Guys thank you very much for your answers, merry christmas guys!
Keep safe âșâșâș
+ 3
so basically putting -1 in length attribute will cause the loop to find the end of a certain value? Did I get it right, by the thanks for the reply it help me a lot.
+ 3
The array.length property gives you the elements's count in the array. But as we know, indexes of the elements starts from 0. So the last element is at index array.length - 1.
Using for-loop:
for (int i = 0; i < array.length; i++) {}
Or for-each loop:
for (String day : days) {}
+ 1
i<data's.length
+ 1
days.length();