0
Java 22.2 Help
This program takes the length of the array as its first input, creates it, and then takes the next input as the elements of the array. 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(); } //enter the code here } } End the program so that it calculates and displays the sum of those numbers in the array that are multiples of 4. Sample input 5 4 9 16 2 7 Result example 20
8 Respuestas
+ 2
Since the inputs are already handled for you, all you need to do is loop over the array and check each element to see if it is a multiple of 4. If it is add its value to the total.
Make an int variable to hold the total.
Make a for loop to loop over the array.
Use the modulus operator to check if the current element is a multiple of 4. If true add it to the total.
After the loop output the total.
+ 1
Igaman Igaman
Instead of just saying it's not working, why don't you post your current version of your code and explain what your current issue(s) are? That way we have a little bit more info to go on.
0
Its not working....
0
Igaman Igaman It'll work try her code Chinmaya Moorthy S
0
Her code not working
0
In the input enter digits with space
0
Not working