import java.util.Scanner;

public class MoreArrays {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		//a different way to create an array
		double[] numbers1 = {2.3, 5.6, 7.8, 2, 9};
		
		//same as
		double[] numbers2 = new double[5];
		numbers2[0] = 2.3;
		numbers2[1] = 5.6;
		//...etc
		
		outputArray(numbers1);
		outputArray(numbers2);
		
		//this is not a copy of the array
		//it is a variable that refers to the same thing
		double[] copyOfNumbers = numbers1;
		copyOfNumbers[0] = -1300;
		outputArray(copyOfNumbers);
		outputArray(numbers1);
		
		doubleValues(numbers2);
		outputArray(numbers2);
		
		//call the readWords method
		String[] words = readWords(input);
		System.out.printf("You entered %d words.\n", words.length);
		
		//print all the words on a line with a space between them
		outputArray(words);
		
	} //main
	
	//print the array given by the parameter
	public static void outputArray(double[] data) {
		//for each item in data
		for(int i = 0; i < data.length; i++) {
			//print it
			System.out.printf("%5.2f ", data[i]);
		}
		System.out.println();
	}
	
	//print the array given by the parameter
	//overloaded
	
	public static void outputArray(String[] data) {
		//for each item in data
		for(int i = 0; i < data.length; i++) {
			//print it
			System.out.printf("%s ", data[i]);
		}
		System.out.println();
	}
	
	
	//double the values in the array
	//arrays are passed by reference
	//does not make a copy
	public static void doubleValues(double[] data) {
		for(int i = 0; i < data.length; i++) {
			data[i] = 2*data[i];
		}
	}
	
	//method to read words from the user and create an array of Strings
	//counting loop
	public static String[] readWords(Scanner in) {
		//find out how many
		System.out.print("How many words? ");
		int n = in.nextInt();
		
		//build the array
		String[] result = new String[n];
		
		//fill the array
		//result.length and n have the same value
		for(int i = 0; i < n; i++) {
			System.out.println("Enter a word: ");
			result[i] = in.next();
		}
		
		//return the result
		return result;
	}
	

} //end of class
