String line = scan.next();
For your input file, the first time you access this, line
will be equal to "A,"
, which is not what you wanted.
This is because Scanner#next()
only reads up until a whitespace character, which is present in the input file between A,
and 0,
. Hence, why only A,
is returned.
Instead use
String line = scan.nextLine();
Which will read up until a line break. So the first loop will set line
to "A, 0, 3"
.
Debugging can really help improve programming abilities. Printing out the return of line
to see what is being processed could have definitely helped with this. Being able to then figure out what is happening to produce those results is a lot easier.