Hello everyone Task number 16 Help

Back to Problem Solutions forum

Popovich Arseny Igorevich     2020-05-28 09:44:10

I did everything right, and in my idea of Java everything works correctly.

Why does the compiler on the site crash, gives such an error

Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:862) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Solution.Solution(Solution.java:23)

at Solution.main(Solution.java:10)

my code

import java.util.*;

public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in);

    int countOperation = 0;
    countOperation = in.nextInt();
    for (int i = 0; i < countOperation; i++) {
        Solution();
    }
}
public static void Solution() {
    Scanner in = new Scanner(System.in);

    ArrayList<Integer> list = new ArrayList<>();
    boolean point = false;
    int inputData = 0;
    int averge = 0;
    int sum = 0;

    while (point == false) {
        list.add(inputData = in.nextInt());
        if (inputData == 0) {
            list.remove(list.size()-1);
            for (int i = 0; i < list.size(); i++) {
                sum += list.get(i);
              averge = sum / list.size();
            }
            System.out.print(averge);
            point = true;
        }
    }
}

}

Prosthetic Conscience     2020-05-28 13:22:01

Never actually programmed in Java, but helping fix code that is not working is, in my opinion, one of the best ways to get an introduction to the language :-)

In your case I have finally arrived at the source of the problem, which is generally described here: Discussion on Stack Overflow. Hope this helps!

Please login and solve 5 problems to be able to post at forum