I have been stuck on this line of code for a while now, it will compile fine but when I run it I get the error: "java.lang.ArrayIndexOutOfBoundsException: 3"
I am trying to input 3 different account numbers and compare them to 3 different account numbers in a file but it will stop me after entering the third account number... not really sure how much code I need to put in there so I will paste most of it here
public static void main(String args) throws FileNotFoundException
Scanner console = new Scanner(System.in);
FileReader dataFile = new FileReader("accountsFile.txt");
Scanner fileIn = new Scanner(dataFile);
andrew cassato wrote:
based on what you said i thought initializing it to 2 would fix it, but that just changed where the error happened so i initialized it to 4 and that fixed it... though i still am not sure why.
The issue isn't how you initialized it -- it is how you used it. Your for loop starts from the second element to the fourth element. You need to modify your for-loop to start from the first element to the third element. IOWs, from element at index zero to element at index 2.