Answer:
Explanation:
import java.util.Scanner;
import java.io.*;
public class ArrayProcessing
{
public static void main(String[] args) throws IOException
{
Scanner kb = new Scanner(System.in);
String fileName;
System.out.print("Enter input filename: ");
fileName = kb.nextLine();
File file = new File(fileName);
if(!file.exists())
{
System.out.println("There is no input file called : " + fileName);
return;
}
int[] numbers = inputData(file);
printArray(numbers);
}
public static int[] inputData(File file) throws IOException
{
Scanner inputFile = new Scanner(file);
int index = 1;
int size = inputFile.nextInt();
int[] values = new int[size];
while(inputFile.hasNextInt() && index < values.length)
{
values[index] = inputFile.nextInt();
index++;
}
inputFile.close();
return values;
}
public static void printArray(int[] array)
{
int count = 1;
for (int ndx = 1; ndx < array.length; ndx++)
{
System.out.printf("%5.f\n", array[ndx]);
count++;
}
if(count == 10)
System.out.println("");
}
}