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
Think of a recent occasion when you became upset with a friend or family member. How did you handle the situation? How did you c
bekas [8.4K]

Answer:

You would identify the problem together with the person or persons involved.

Explanation:

4 0
2 years ago
What does the following function return? void index_of_smallest(const double all, int startindex, int numberOfSlots); A. a doubl
Flauer [41]

Answer:

nothing

Explanation:

Because the return type of the function is void. void means does not return any thing.

The syntax of the function:

type name( argument_1, argument_2,......)

{

  statement;

}

in the declaration the type define the return type of the function.

it can be int, float, double, char, void etc.

For example:

int count( int index);

the return type of above function is int. So, it return integer.

similarly,

void count(int index);

it return type is void. So, it does not return any thing.

7 0
3 years ago
? An attempt to harm damage or cause threat to a system or network is broadly termed as
Radda [10]

Answer:

A cyber attack or hacking

Explanation:

6 0
2 years ago
A grade of B is worth Grade points<br><br><br> A) 3.0<br> B) 80<br> C)2.0<br> D)4.0
Elodia [21]

Answer:

I am pretty sure. In my view answer is 4.0

8 0
3 years ago
Read 2 more answers
In which of the following is “y” not equal to 5 after execution? X is equal to 4.
Step2247 [10]

Answer:

d) y=x++

Explanation:

In all 3 statements:

y= ++x;

y=x=5;

y=5;

The value of y is equal to 5.

However in the statement y=x++, the value of 5 is equal to value of x prior to the increment operation. The original value of x was 4. So the value of y will be 4. Note that after the statement execution, the value of x will be updated to 5. In effect y=x++ can be visualized as a sequence of following steps:

x=4;

y=x;

x=x+1;

5 0
3 years ago
Other questions:
  • "Suppose that instead of always selecting the first activity to finish, we instead select the last activity to start that is com
    14·1 answer
  • You're browsing the Internet and realize your browser is not responding. Which of the following will allow you to immediately ex
    5·2 answers
  • How does Hadoop work? It breaks up Big Data into multiple parts so each part can be processed and analyzed at the same time on o
    5·1 answer
  • Liz's meeting is scheduled to end at 9:30. It is 9:20 and team
    9·1 answer
  • You asked your colleague to provide feedback on a blog post you recently wrote. When they sent you their feedback, they made edi
    10·1 answer
  • Joel has left his computer unattended while answering a phone call. A TV repairer in his house tries to surf through the applica
    13·1 answer
  • Examples of analog computer
    8·1 answer
  • The Clean Air Act Amendments of 1990 prohibit service-related releases of all ____________. A) GasB) OzoneC) MercuryD) Refrigera
    15·1 answer
  • How to make your nest learning thermostat stop doing something
    14·1 answer
  • How do you get your winkey wet??
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!