Java 22.2 Help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

29th Apr 2021, 4:53 AM
Igaman Igaman
Igaman Igaman - avatar
8 Answers
+ 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.
29th Apr 2021, 5:00 AM
ChaoticDawg
ChaoticDawg - avatar
+ 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.
1st May 2021, 12:36 PM
ChaoticDawg
ChaoticDawg - avatar
30th Apr 2021, 9:20 AM
Chinmaya Moorthy S
Chinmaya Moorthy S - avatar
0
Its not working....
30th Apr 2021, 10:23 AM
Igaman Igaman
Igaman Igaman - avatar
0
Igaman Igaman It'll work try her code Chinmaya Moorthy S
30th Apr 2021, 10:25 AM
kreddyt
kreddyt - avatar
0
Her code not working
30th Apr 2021, 10:26 AM
Igaman Igaman
Igaman Igaman - avatar
0
In the input enter digits with space
30th Apr 2021, 10:28 AM
kreddyt
kreddyt - avatar
0
Not working
1st May 2021, 12:12 PM
Igaman Igaman
Igaman Igaman - avatar