This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Sorting a numerical Array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sorting a numerical Array" Watch "Sorting a numerical Array" New topic

Sorting a numerical Array

valaree k.

Joined: Nov 20, 2005
Posts: 1
Hello everyone!
I am working on a small project for school with the following requirements:
- Create a program that requests the user to enter five integers
- Place these values into an array called myArr
- Type any sorting method into this program that will sort the array myArr
Here is my code:

This is the exception I am getting:

I am lost =(
Any help or suggestions would be much appreciated!
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 104


The java.lang.ArrayIndexOutOfBoundsException means that your are trying to access an array object with an index larger than the current data inside the array.

Array in Java is zero indexed, which means the array index start from zero. So if you have five items in it (array length = 5) it means the index if from 0 to 4. In your code you have five items in the array, this mean the maximum array index is 4.

To fix the error in your code you have to change the for loop condition check in insertionSort() method.


Website: Learn Java by Examples
I agree. Here's the link:
subject: Sorting a numerical Array
Similar Threads
cannot resolve symbol
Array problem
static final int[] wont print unsorted column
cannot resolve a symbol with a method.