// NewFindMax.java
// Aaron Tan
// This program finds the largest value in an integer array.
// This is a "modularized" version of FindMax.java

import java.util.*;

public class NewFindMax {

  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();

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

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

  } // main

  // Returns the largest value in arr
  public static int computeMax(int[] arr) {

    int max = arr[0];
    for (int i=1; i<arr.length; i++) 
       if (arr[i] > max)
          max = arr[i];

    return max;

  } // computeMax

  // Returns the index of the largest value in arr
  // If there are more than one largest value, return the
  // smallest index among them.
  public static int computeIndexOfMax(int[] arr) {

    int indexOfMax = 0;
    for (int i=1; i<arr.length; i++) 
       if (arr[i] > arr[indexOfMax])
          indexOfMax = i;

    return indexOfMax;

  } // computeIndexOfMax

}

