Please help with practic 60.2 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Please help with practic 60.2

import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[ ] args) { Scanner scanner = new Scanner(System.in); ArrayList<Integer> evennums = new ArrayList<Integer>(); while(evennums.size()<3){ int num = scanner.nextInt(); //введите код сюда } //вычислите и выведите в результат среднее всех значений целых чисел } }

4th Dec 2022, 7:30 AM
Кирило Шмуш
Кирило Шмуш - avatar
2 Answers
+ 3
Кирило Шмуш please show us your attempt not the pre-set structure of code which sololearn has already supplied. будь ласка, покажіть нам свою спробу, а не попередньо встановлену структуру коду, яку sololearn уже надав.
4th Dec 2022, 8:18 AM
BroFar
BroFar - avatar
+ 2
Inside the while loop, use the add() method of the arraylist to put the input values into the list. Then you need to calculate the average. There are several options to do it, the most basic one is set an int variable to zero, and loop through all elements of the arraylist and add each value to the sum. Then divide by 3 (which is the final size of the arraylist) to get the average, and print it to the screen.
4th Dec 2022, 11:28 AM
Tibor Santa
Tibor Santa - avatar