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.

6th Sep 2022, 12:01 PM
Alex Velikiy
Alex Velikiy - avatar
2 Respostas
0
Your attempt?
6th Sep 2022, 12:37 PM
Jayakrishna 🇮🇳
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); }
6th Sep 2022, 1:11 PM
Stephan Peters
Stephan Peters - avatar