132k views
1 vote
Create a static method called findlargest, which takes an array of integers as an input parameter and returns the array index of the largest integer in the array. if there are positions that are tied for largest, the method should return the first index with a largest value.

User Valmo
by
7.1k points

1 Answer

5 votes
public static int findlargest( int[] theArray )
{
int index = 0;
int maxVal = 0;
for( int i = 0; i < theArray.length; i++ )
{
if( theArray[ i ] > maxVal )
{
maxVal = theArray[ i ];
index = i;
}
}
return( index );
}
User Neil Coffey
by
7.4k points