import java.util.Scanner;
import java.io.PrintWriter;
import java.io.File;
import java.io.FileNotFoundException;

class Oct27 {

	public static void main(String[] args) {

		Scanner kb = new Scanner(System.in);
		System.out.println("Enter size of array: ");
		int size = kb.nextInt();

		int[] arr = new int[size];

		// ask for value - populate array
		System.out.println("Enter value: ");
		int value = kb.nextInt();

		for(int i = 0; i < arr.length; i++) {
			arr[i] = value;
		}

		printArray(arr);

		PrintWriter pw = null;
		
		try {
			File file = new File("oct27.txt");
			pw = new PrintWriter(file);
		}
		catch(FileNotFoundException e) {
			System.out.println("Cannot open file for writing");
			return;
		}

		pw.println("Contents of array");

		for(int elm : arr) {
			pw.printf("%d ", elm);
		}		

		pw.close();  // flush buffer to file		

	}
	
	static void printArray(int[] a) {
		for(int elm: a) {
			System.out.printf("%d ", elm);
		}
		System.out.println();
	}
}
