//File:	NumberList.java
import iostuff.*;
public class NumberList
{
	public static int [] inputList ()
	{
		System.out.print ("How many items in your list? ");
		int n=Keyboard.readInt();
		
		//allocate n memory locations for array x
		int [] x = new int [n];
		
		//fill the array x with values from the user
		for (int k=0; k<n; k++)
		{
			System.out.print ("Next number please: ");
			x [k] = Keyboard.readInt();
		}
		
		return x;	//return the filled array x
	}
	
		
	//NOTE:	In the following, length is an instance variable
	//	associated with an array object.  It carries the
	//	the size of the array, NOT necessarily the number
	//	of items input to the array.
	
	
	//The following method finds the smallest item in a list of integers
	public static int smallest (int [] list)
	{
		int smallestSoFar;
		
		//The following focuses on smallestSoFar,
		//a variable that is compared with each item
		//in the list in succession.  As smaller items
		//are encountered, they are assigned to the variable
		//smallestSoFar.
		smallestSoFar = list[0];
		for (int k=1; k<list.length; k++)
		{
			if (list[k] < smallestSoFar)
			{
				smallestSoFar = list[k];
			}
		}
		return smallestSoFar;
	}
	
	//The following method outputs to the screen a list of integers
	public static void display (int [] list)
	{
		for (int k=0; k<list.length; k++)
		{
			System.out.println (list[k]);
		}
	}
	
	public static int average (int [] a)
	{
		int sum=0;
		for (int k=0; k<a.length; k++)
		{
			sum = sum + a [k];
		}
		return sum/a.length;
	}
	
	public static double average (double [] a)
	{
		double sum=0;
		for (int k=0; k<a.length; k++)
		{
			sum = sum + a [k];
		}
		return sum/a.length;
	}
	
	public static int sd (int [] a, int average)
	{
		int sum=0;
		for (int k=0; k<a.length; k++)
		{
			sum = sum + (a[k]-average) * (a[k]-average);
		}
		return (int) Math.sqrt(sum/a.length);
	}	
}