Search code examples
javajava.util.scannernosuchelementexception

NoSuchElementException doesn't pass a test on Ideone


Please could you tell me what I did wrong. I think my code works correctly but doesn't pass a test on Ideone.

do{
    linia = reading.nextLine();
    try{
        number = Integer.parseInt(linia);
        if(number < 100 && number > -100) {
                sum += number;
                resultList.add(sum);
        }
    }catch(NumberFormatException e){
        //System.out.println("Niepoprawne dane !");
        end = true;
    }
}while(!end);

if(resultList != null) {
    for (int i = 0; i < resultList.size(); i++) {
        System.out.println(resultList.get(i));
    }
} 

Solution

  • Issue is that in your code, you accept the input on command line from the user using code linia = reading.nextLine(); which is not possible with the IDEONE (online editor) As there it can't supply the user input.

    Thats the reason it was working fine locally but failing when you run it on IDEONE.

    Removing the code, which ask user input will solve the issue.