// FindMax.java
// Aaron Tan
// This program finds 
// (1) the largest value in an integer array,
// (2) the index of the largest value.

import java.util.*;

public class FindMax {

  public static void main(String[] args) {

    Scanner stdIn = new Scanner(System.in);
 
    System.out.print("Size of array: ");
    int sizeArray = stdIn.nextInt();

    int[] values = new int[sizeArray];

    // Read values into array
    System.out.print("Enter " + sizeArray + " values: ");
    for (int i=0; i<values.length; i++) 
       values[i] = stdIn.nextInt();

    // Find the largest value
    int max = values[0];
    for (int i=1; i<values.length; i++) 
       if (values[i] > max)
          max = values[i];

    System.out.println("The largest value is " + max);

    // Find the index of the largest value.
    // If there are more than one largest value,
    // find the smallest index among them.
    int indexOfMax = 0;
    for (int i=1; i<values.length; i++) 
       if (values[i] > values[indexOfMax])
          indexOfMax = i;

    System.out.println("The largest value is at index " + indexOfMax);

  }

}


