- 1
Complete the program to go through the array and calculate the sum of the numbers that are multiples of 4.
Can anyone help me with this program?
5 odpowiedzi
+ 2
Thnx mate for the solution :)
+ 1
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int length = scanner.nextInt();
int[] array = new int[length];
for (int i = 0; i < length; i++) {
array[i] = scanner.nextInt();
}
//your code goes here
double sum = 0.0;
if(array[i] % 4 == 0){
sum += array[i];
}
System.out.println(sum);
}
}
0
Yes , can you show us your attempt please ?
Also use relevant language name as tags .
0
Please, show us your attempt first. Or you do not understand the task?
0
You should iterate through array and the "if" statement should be checked at each iteration.
Fixed version:
https://code.sololearn.com/cv53Eec7J1PE/?ref=app