Note
You used Arrays.sort(arg) method repeatedly since that statement is inside your loop


for(int j = 0; j < theArray.length; j++)
{
Arrays.sort(theArray);
...