 <p>One way to do it can be saving largest index, not value. You also need to return some value in case of empty array:</p> <pre><code>public static int largest(int[] nums3) { if (nums3.length == 0) { return -1; } int largestIndex = 0; for(int i=0; i &lt; nums3.length; i++) { if(nums3[i] &gt; nums3[largestIndex]) { largestIndex = i; } } return largestIndex; } </code></pre>