0
Компилятор в задании сломан не могу решить задачу связанную с Arraylist
The program you are given declares an even nums ArrayList. Write a program to take numbers as input and add them an ArrayList while the size of the ArrayList isn't equal to 3. Then calculate and output the average of all values in integers.
2 ответов
0
Your attempt?
0
Something like this?
Scanner scanner = new Scanner(System.in);
ArrayList<Integer> evenNums = new ArrayList<>();
String input;
int nextInt;
int total = 0;
do {
input = scanner.nextLine();
if (input.equals("")) break;
nextInt = Integer.parseInt(input);
evenNums.add(nextInt);
} while (evenNums.size() < 2);
for (int num : evenNums) {
total = total + num;
}
total = Math.round(total / evenNums.size());
System.out.println(total);
}