
/*
	Write a method named max that has one parameter.  
	The paramter is named arr and holds an array of integers.
	The method returns the largest value in the array passed in as an argument.

	Write a method named setArrayFromKeyboard that takes an array of integers
	as an argument, asks the user to enter in a number of integers equal
	to the length of the array and stores the integers in the array.

*/

import java.util.Scanner;

class Sep20 {

	static int max(int[] arr) {
		//int max = arr[0];
		int max = Integer.MIN_VALUE;
		//int count = 1;
		int count = 0;
		while(count < arr.length) {
			if(arr[count] > max) {
				max = arr[count];
			}
			count++;
		}
		return max;		
	}

	static void setArrayFromKeyboard(int[] arr) {
		int len = arr.length;

		System.out.println("Enter " + len + " integers:");
		Scanner kb = new Scanner(System.in);

		int count = 0;
		while(count < len) {
			arr[count] = kb.nextInt();
			count++;
		}
		kb.close();
	} 


	public static void main(String[] args) {

		int[] array = new int[5];

		setArrayFromKeyboard(array);

		int max = max(array);
		System.out.println("max value: " + max);

		// change the element whose position is in index to newValue
		int index = 3;
		int newValue = 5;
		
		arr[index] = newValue;
		
	


	}
}
