Back to Problem Solutions forum
I did everything right, and in my idea of Java everything works correctly.
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)
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;
}
}
}
}
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!