#need help getting rid of confusing exception in java program

1 messages · Page 1 of 1 (latest)

summer spoke
#

I am creating a program that takes a file with a bunch of double values (which I have attached), calculates a bunch of statistics from it, such as the amount of numbers that are negative, between zero and 100, and greater than 100, and those results are then output to another file. However, I keep getting a NoSuchElementException and don't know what's wrong.
code is also attached

ruby edge
#

I'm not sure about the exception you had, I try to run the code on my editor but couldnt read any data from the file.
I ended up using

 while (input.hasNextLine()) {
                inputNumber = parseDouble(input.nextLine());
                //int lineInt = Integer.parseInt(line);
                lineCounter++;
                //String str = new String(line);

                if (inputNumber < 0) {
                    negNum += 1;
                }
                if (inputNumber >= 0 && inputNumber < 100) {
                    btw0and100 += 1;
                }
                if (inputNumber > 100) {
                    geq100 += 1;
                }
            }

instead of input.hasNextDouble() since it was always returning false.
it seems to work with that @summer spoke

summer spoke
#

@ruby edge thank you!

#

it works perfectly

ruby edge
#

nice np !

wraith tundra
#

NoSuchElementException

you have to check for hasNext()

#

also you are leaking ressource and memory on failure

#