// ITI 1120
// Name: Diana Inkpen, Student# 123456

//import java.io.*;

/**
 * This program computes the maximum value in an array.
 * Ex 6.16 in lecture notes
 */

class MaxInArray
{
    public static void main (String[] args)
    {
        // DECLARE VARIABLES/DATA DICTIONARY 
        int [] a;        
        int result;  

        // READ IN GIVENS
        System.out.println( "Please enter the array:" );
        a = ITI1120.readIntLine( );
        
        // CALLS THE ALGORITHM
        result = maxInArray(a);
            
        // PRINT OUT RESULTS AND MODIFIEDS
        System.out.println( "The maximum is " + result );
    }

     public static int maxInArray ( int [] a)
     {  
       // VARABLE DECLARATIONS
        int index;  // intermediate
        int max;    // RESULT
        
        //BODY OF THE ALGORITHM
        max = a[0];    
        index = 1;  
        while (index < a.length)
        {
          if (a[index] > max)
          {
            max = a[index];  // update max
          }
          index = index + 1;
      }

      // Return results
      return max;
     }
} 
