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 of the following is an open-source web browser?
rosijanka [135]
That answer would be internet explorer
8 0
3 years ago
Read 2 more answers
Give a big-O estimate for the number of comparisons used by the algorithm that determines the number of 1s in a bit string of le
Illusion [34]
The notation would be O (n-1) because there would be no need to compare with the first bit however this notation is most commonly noted as O (n) but the first is also technically correct
3 0
2 years ago
Read 2 more answers
why might a portrait be both a portrait of the subject and the photographer? how is a photographer present in a portrait?
Nataliya [291]
Because of the reflection on the window or mirror.
5 0
2 years ago
Read 2 more answers
Write an If/else statement to check whether host is online. If it is online, then print system is online otherwise print system
Reika [66]

Answer:

from socket import *

hostname = input('Enter the host to be scanned: ')

ip_add = gethostbyname(hostname)

connections = [ ]    

for i in range(133, 136):

   s = socket(AF_INET, SOCK_STREAM)

     

   conn = s.connect_ex((ip_add, i))

   print(conn)

   connections.append(conn)

if 0 in connections:

   print ('Host is online')

   s.close()

else:

   print ('system is unreachable')

Explanation:

The python source code above scans for all the available range of ports in the provided hostname, if any port is available, the host is online else the program print the error message "system is unreachable.

4 0
3 years ago
What is input process<br>​
riadik2000 [5.3K]

Answer:

describing the structure of an information processing program or another process. Many introductory programming and systems analysis texts introduce this as the most basic structure for describing a process.

Explanation:

  • A requirement from the environment (input)
  • A computation based on the requirement (process)
  • A provision for the environment (output)

Example: A small engineering firm believes there are problems with its hiring process. Several of the junior engineers that have been hired remained at the firm for less than one year. This is a considerable cost to the firm, since recruiting and training new engineers is time consuming and expensive. The human resources manager decides to put together a group of people with extensive experience hiring new engineers. One of their first tasks is to produce an input-output model of the hiring process. They generate the following.

4 0
2 years ago
Other questions:
  • What is the best class setup for the mp5 in Modern Warfare?
    7·1 answer
  • The entire presentation can be seen at a time in __________
    5·1 answer
  • Create a static method called fillArray, which takes an integer array as an input parameter, along with an integer initial value
    12·1 answer
  • When changing lanes on an expressway signal your intentions and?
    8·1 answer
  • A type of touch screen that can be up to four feet by six feet is a(n) _____.
    12·2 answers
  • Display all the natural numbers from 1 to 100 that are exactly divisible by 3 and 7 using FOR … NEXT. Without using Mod
    7·1 answer
  • Please help thank you !!!
    7·2 answers
  • MULTIPLE CHOICE QUESTION
    14·2 answers
  • What is the answer ????​
    13·2 answers
  • Michelle has defined a custom object by creating an object literal. She wants to access the properties of the custom object. Mic
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!