I am supposed to write a program that finds the largest index in an unsorted array of integers.
Use a method that takes an array of integers as a parameter. The method should search the array and return the index of the largest value.
So i wrote a program that returns the highest value, for example it returns 13 as the highest number instead of the index of 2. So how would i return the index instead of the highest number itself? If that is an easy fix, does the rest of my code look correct? Thanks!
public class LargestInteger
{
public static void main(String[] args)
{
int[] largeArray = {5,4,13,7,7,8,9,10,5};
System.out.println(findLargest(largeArray));
}
public static int findLargest(int array[])
{
int largest = array[0];
for(int i = 0; i < array.length; i++)
{
if(array[i] > largest)
largest = array[i];
}
return largest;
}
}