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
Which is NOT a way the network operating sys-
irakobra [83]

Answer: A user authentication

3 0
3 years ago
How can you skillfully use the internet for research
elena-s [515]

By looking up your research on websites that have (.org) or wikipedia for answers u might have to find information

6 0
3 years ago
Amye is in high school. As part of one of her classes, she had to identify the legality of different situations that involved
adell [148]
I say you should pick answer 1. an HR makes more sense since she is interested in a topic about the legality of different situations that are related to workers and their employers.
8 0
2 years ago
Read 2 more answers
The count formula will tell you how many cells have a number in them, NOT the total number of cells with any value in them. True
Talja [164]

Answer:

false

Explanation:

hope it helps :)

4 0
2 years ago
When preparing to communicate a solution to a design problem, you must:?
damaskus [11]
You must Examine the viewpoint of ur audiences
7 0
3 years ago
Other questions:
  • Var cookie = "username=mike2009";
    10·1 answer
  • The local emergency manager has the responsibility for coordinating emergency management programs and activities. A local emerge
    7·1 answer
  • Which biometric technique is considered nearly infallible from a scientific point of view and is increasingly preferred by crimi
    8·1 answer
  • Apple users tend to like the company and love its products. Apple has successfully nurtured this __________ component of its cus
    15·1 answer
  • EDVAC stands for? on which theory it is made on?
    15·1 answer
  • What protocol communicates data between routers representing the edges of autonomous systems?Distance-vectorLink stateInterior g
    11·1 answer
  • How would you justify using cloud computing?
    12·1 answer
  • Similarities between inline css and internal css​
    6·1 answer
  • In design and implementation of any _____ reasoning application, there are 4 Rs involved: retrieve, reuse, revise, and retain.
    7·1 answer
  • What are 3 customizations that can be done using the header/footer section in the customize reports tray?.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!