So I'm working on a program that so far
1) reads a set of numbers from an input file, puts them into an array. The array length is a constant number, but the input file (I run the program twice with different input files) either has more or less then the array size. I'm supposed to count the number of elements in the file including the ones which didnt fit in the array.
This is my code so far.
import java.util.Scanner; import java.io.*; public class QudratullahMommandi_3_10 { public static void main(String[] args) throws IOException { final String inputFile = "QudratullahMommandi_S_10_Input_Set1.txt"; final String outputFile = "QudratullahMommandi_S_10_Output_Set1.txt"; int numOfItems; // num of items in the array final int arrayLength = 15; // setting the array length int[] indexHolder; double[] valueHolder = new double[arrayLength]; // values from input // opening input file File file = new File(inputFile); Scanner input = new Scanner(file); // Putting values into the array and getting back the num of items in the array // then outputting the num of items numOfItems = arraysorter(valueHolder,input); System.out.println(numOfItems); } public static int arraysorter(double[]arrayVals, Scanner input) { int subMarker = 0; int numOfItems = 0; int arrayLength = arrayVals.length; int index = 0; while (input.hasNext()) { numOfItems++; if (index < arrayLength) { arrayVals[index] = input.nextDouble(); index++; } } return numOfItems; }// end array Sorter }// end class
I'm getting some kind of error where it compiles fine but when I run it, the program never ends. I don't get any output or error messages, it stays running and just never ends... and never outputs anything either.
This is what my input file I'm using looks like
88
80
66
99
22
88
54
100
77
29
100
98
66
11
73
98
100
7
21