0

I need just explanation not solution check the link

https://www.sololearn.com/coach/63?ref=app What they are exactly asking for in their problems? I solve it but for only case one and two. I don't know what they want me to do to make it works for all the cases. Any suggestions? I solved it in java and I am pretty sure the code is correct and I am not asking to give me the answer, I just want to know what's wrong with mine

3rd Oct 2020, 11:29 PM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar
3 Réponses
+ 1
You have to take input from the user your program is right but you specified the variables although you should take the number of variables from the user and then create the array with the same length and let the user input the array numbers I modified a little on your code import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc =new Scanner(System.in); int n = sc.nextInt(); int sum=0; int N[] = new int[n]; for(int i=0; i<N.length; i++){ N[i] = sc.nextInt(); if(N[i]%2==0){ sum=sum+N[i]; } } System.out.println(sum); } }
4th Oct 2020, 2:31 AM
Ruba Kh
Ruba Kh - avatar
+ 1
Ruba Kh thank you so much Ruba for the help
4th Oct 2020, 2:35 AM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar
0
blackwinter here is my code import java.util.ArrayList; public class Program { public static void main(String[] args) { int[] N ={5,190,88}; //int[] N ={1,191}; //int N = list.length; int sum=0; for(int i=0; i<N.length; i++){ if(N[i]%2==0){ sum=sum+N[i]; } } System.out.println(sum); } }
4th Oct 2020, 2:12 AM
Khaled ^^ خالد القريشي‎
Khaled ^^ خالد القريشي‎ - avatar