1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
stiks02 [169]
3 years ago
15

The divBySum method is intended to return the sum of all the elements in the int array parameter arr that are divisible by the i

nt parameter num. Consider the following examples, in which the array arrcontains {4, 1, 3, 6, 2, 9}.
The call divBySum(arr, 3) will return 18, which is the sum of 3, 6, and 9, since those are the only integers in arr that are divisible by 3.
The call divBySum(arr, 5) will return 0, since none of the integers in arr are divisible by 5.
Complete the divBySum method using an enhanced for loop. Assume that arr is properly declared and initialized. The method must use an enhanced for loop to earn full credit.
/** Returns the sum of all integers in arr that are divisible by num
* Precondition: num > 0
*/
public static int divBySum(int[] arr, int num)
Computers and Technology
1 answer:
iragen [17]3 years ago
8 0

Answer:

The complete method is as follows:

public static int divBySum(int[] arr, int num){        

     int sum = 0;

     for(int i:arr){

         if(i%num == 0)

         sum+=i;

     }

     return sum;

   }

Explanation:

As instructed, the program assumes that arr has been declared and initialized. So, this solution only completes the divBySum method (the main method is not included)

This line defines the method

public static int divBySum(int[] arr, int num){        

This line declares and initializes sum to 0

     int sum = 0;

This uses for each to iterate through the array elements

     for(int i:arr){

This checks if an array element is divisible by num (the second parameter)

         if(i%num == 0)

If yes, sum is updated

         sum+=i;

     }

This returns the calculated sum

     return sum;

   }

You might be interested in
Liza works as a receptionist. Around the lunch hour, she has a difficult time hearing the callers due to employees talking near
Rashid [163]
c.<span>barriers to communication
 because the other employees are the ones causing the trouble</span>
6 0
3 years ago
Initially, later, and finally are examples of what kind of words
Klio2033 [76]
Im pretty sure that the correct answer is Transition words.
3 0
3 years ago
What would the range(3, 9) function generate?
gregori [183]

Answer:

A, 3,6,9

is the answer

Explanation:

bc it count by

3 0
2 years ago
How do i make a PDF and what is a PDF<br><br> sorry i am dumb
Soloha48 [4]

Answer:

............................................

Explanation:

5 0
2 years ago
Cloud computing will offer applications that are _______.
Komok [63]
B. only accesible over the internet
8 0
3 years ago
Read 2 more answers
Other questions:
  • Netflix suggestions ?
    15·2 answers
  • Technology has changed the way functions are performed in the law office. Which function has been the least affected by technolo
    10·1 answer
  • Who is the last person appointed to the u.s supreme court
    11·1 answer
  • Your organization recently deployed a Windows domain controller with Active Directory. All the domain OU users need to run the s
    11·1 answer
  • anyone got a class named computer literacy? or sum similar to using Microsoft programs? i need a lotttt of help, im 3 units behi
    12·2 answers
  • Why are free web based providers so popular?
    12·1 answer
  • Radio waves can be used to transmit energy. What is an advantage of this method in computer technology
    7·2 answers
  • HELP ME PLZZZ I'll give brainist​
    9·1 answer
  • How do you convert an algorithm to make it possible for a computer to read
    6·1 answer
  • Software that converts program written in other language into machine language​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!