Thread: array max num
View Single Post
Old 04-09-2003, 12:08 PM   #1 (permalink)
Apodysophilia
Regular Contributor
 
Apodysophilia's Avatar
 
Join Date: Apr 2003
Location: noWhere, PA
Posts: 104
Apodysophilia is on a distinguished road
Send a message via AIM to Apodysophilia
array max num

omg, I feel so stupid


but,


Code:
     public int maxElt(int[] ary)
     {
          int asdf = 0;
          
          for( int aryIndex = 0; getSize() > aryIndex; aryIndex++) 
          { 
              if(ary[aryIndex] > ary[(aryIndex+1)])
              {
                         
                         asdf = ary[ ary[(aryIndex+1)] ];
             
               }
               else
               {
                         asdf = ary[aryIndex];
               }
          
          } 
          return asdf;
     }
the error message
Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
        at TestAry.maxElt(TestAry.java:73)
i know whats wrong it is trying to get one more then the array is, But for the life of me i can't figure out what is wrong (i think i need to sleep more)if i figure it out 10min after i post this i gonna hate myself

any help would be aprecaded, the method is supposed to return the highest value in an int array
Apodysophilia is offline   Reply With Quote