+ 1

Thats odd

Help, error in case 4 and 5. I dont know what its wrong. import java.util.Scanner; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Program { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList <Integer> list = new ArrayList <Integer>(); while(in.hasNextInt()){ list.add(in.nextInt()); } Integer[] arr = new Integer[list.size()]; arr = list.toArray(arr); int even = 0; for(int i=0; i<arr.length; i++){ if(arr[i]%2==0){ even += (arr[i]); } } System.out.println(even); } }

5th Nov 2020, 1:33 PM
Iñaki Lapeyre
1 ответ
+ 2
Read the description again.. The first input is the number of values to be taken into list or array...
5th Nov 2020, 2:08 PM
Jayakrishna 🇮🇳