63 193
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #19845 in Java | JSP | JSF for nohra

Question #19845
46-8. You coded the following on lines 26, 27, and 28 of the class Test.java:
int[]a={2,7,8,9,11,16}; //line26ofclassTest.java
for ( int i = 0; i <= a.length; i++ ) // line 27 of class Test.java
System.out.println( a[i] ); // line 28 of class Test.java

The code compiles properly, but when you run, you get the following message:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at Test.main ( Test.java:28 )

Explain what the problem is and how to fix it.
Expert's answer
You need to write like this:
for (int i = 0; i < a.length; i++)

In this case, exception ArrayIndexOutOfBoundsException will not appear

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions