Hello guys, I've been trying to make a program that takes the IDs from a file and make them into a 1D array.
The input file looks like this :
201053420
201052456
201488540
201384345
And it should be working even if there's more than 4 IDs.
import java.util.*;
import java.io.*;
public class Assign6 {
public static void main(String[] args) throws FileNotFoundException {
Scanner stuID = new Scanner(new File("ICS102.txt"));
int numOfID = 0;
while (stuID.hasNextInt()) {
numOfID++;
}
System.out.println(numOfID);
int [] IDs = new int [numOfID];
for (int i = 0; i < numOfID; i++ ) {
IDs[i] = stuID.nextInt();
}
for (int i = 0; i<numOfID; i++)
System.out.println(IDs[i]);
}
}
Apparently there's a problem in the first while loop, I don't know why. If someone can help me with and explain, I'd be thankful.