File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes ArrayIndex OutOfBoundsException? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ArrayIndex OutOfBoundsException?" Watch "ArrayIndex OutOfBoundsException?" New topic

ArrayIndex OutOfBoundsException?

Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
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:
java.lang.ArrayIndex OutOfBoundsException: 5
at NB2A71.main(
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

Joined: Oct 25, 2000
Posts: 7292

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.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
I agree. Here's the link:
subject: ArrayIndex OutOfBoundsException?
It's not a secret anymore!