Back to Problem Solutions forum
package com.company; import java.util.ArrayList; import java.util.Scanner;
public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int countOperation = 0;
System.out.print("Введите количество операций: ");
countOperation = in.nextInt();
for (int i = 0; i < countOperation; i++) {
Solution();
}
}
public static void Solution() {
ArrayList<Integer> list = new ArrayList<>();
int countOperation = 0;
boolean point = false;
int inputData = 0;
int averge = 0;
int sum = 0;
Scanner in = new Scanner(System.in);
System.out.println("Введите значения: ");
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.println(averge);
point = true;
}
}
}
}
Hi Friend!
Not sure what you may mean by "not compile"... The "sandbox" used by the site may not work sometimes, but anyway you should be able to submit answer calculated with running code locally.
BTW generally you don't want spare outputs in the code as they will be included along with answer:
System.out.println("Введите значения: ");