Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayIndex OutOfBoundsException?

 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a class that solves linear equation system with LU-decomposition algorithmus. I got the error message when ran it:
Please enter an integer as the size of the matrix:
5
java.lang.ArrayIndex OutOfBoundsException: 5
at NB2A71.main(NB2A71.java:31)
Press any key to continue...
The source code is as following:

In this program, the initial values of a[i][j] and b[i] are specified here:

How should I modify the code so that it can run? Thank you very much in advance!
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays start at zero, so that valid index range of your arrays will be 0 through 4. Modify the loop so that 5 cannot be a counter value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic