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
nlexa [21]
3 years ago
11

Given an array as follows

Computers and Technology
1 answer:
slava [35]3 years ago
5 0

Answer:

1) Method calcTotal:

  1. public static long calcTotal(long [][] arr2D){
  2.        long total = 0;
  3.        
  4.        for(int i = 0; i < arr2D.length; i++ )
  5.        {
  6.            for(int j = 0; j < arr2D[i].length; j++)
  7.            {
  8.                total = total + arr2D[i][j];
  9.            }
  10.        }
  11.        
  12.        return total;
  13.    }

Explanation:

Line 1: Define a public method <em>calcTotal</em> and this method accept a two-dimensional array

Line 2: Declare a variable, total, and initialize it with zero.

Line 4: An outer for-loop to iterate through every rows of the two-dimensional array

Line 6: An inner  for-loop to iterate though every columns within a particular row.

Line 8: Within the inner for-loop, use current row and column index, i and j, to repeatedly extract the value of each element in the array and add it to the variable total.

Line 12: Return the final total of all the element values as an output

Answer:

2) Method calcAverage:

  1. public static double calcAverage(long [][] arr2D){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            for(int j = 0; j < arr2D[i].length; j++)
  8.            {
  9.                total = total + arr2D[i][j];
  10.                count++;
  11.            }
  12.            
  13.        }
  14.        
  15.        double average = total / count;
  16.        
  17.        return average;
  18.    }

Explanation:

The code in method <em>calcAverage</em> is quite similar to method <em>calcTotal</em>. We just need to add a counter and use that counter as a divisor of total values to obtain an average.

Line 4: Declare a variable, count, as an counter and initialize it to zero.

Line 11: Whenever an element of the 2D array is added to the total, the count is incremented by one. By doing so, we can get the total number of elements that exist in the array.

Line 16: Use the count as a divisor to the total to get average

Line 18: Return the average of all the values in the array as an output.

Answer:

3) calcRowAverage:

  1. public static double calcRowAverage(long [][] arr2D, int row){
  2.        double total = 0;
  3.        int count = 0;
  4.        
  5.        for(int i = 0; i < arr2D.length; i++ )
  6.        {
  7.            if(i == row)
  8.            {
  9.                for(int j = 0; j < arr2D[i].length; j++)
  10.                {
  11.                    total = total + arr2D[i][j];
  12.                    count++;
  13.                }
  14.            }
  15.            
  16.        }
  17.        
  18.        double average = total / count;
  19.        
  20.        return average;
  21.    }

Explanation:

By using method <em>calcAverage </em>as a foundation, add one more parameter, row, in the method <em>calcRowAverage</em>. The row number is used as an conditional checking criteria to ensure only that particular row of elements will be summed up and divided by the counter to get an average of that row.

Line 1: Add one more parameter, row,

Line 8-15: Check if current row index, i, is equal to the target row number, proceed to sum up the array element in that particular row and increment the counter.

You might be interested in
You have been asked to advise a group of several universities who want to combine research efforts and store data in the cloud.
inn [45]

Community cloud is best for a group of several universities who want to combine research efforts and store data in the cloud.

<h3>Community cloud</h3>

Community cloud allows for the flexibility and scalability normally found in a public cloud, but it also limits the number of users to a smaller, trusted group.

  • When multiple organizations with similar objectives want to combine efforts in a cloud, the best choice is generally a community cloud.

Community cloud is best for a group of several universities who want to combine research efforts and store data in the cloud.

Find out more on community cloud at: brainly.com/question/25620318

4 0
2 years ago
Which backup requires a small amount of space and is considered to have an involved restoration process?
dusya [7]

Incremental backup needs a small amount of space and exists considered to have an involved restoration process.

<h3>What is Incremental backup?</h3>

A backup or data backup exists as a copy of computer data taken and stored elsewhere so that it may be utilized to restore the original after a data loss event. The verb form, directing to the process of doing so, exists as "back up", whereas the noun and adjective form is "backup".

An incremental backup exists a backup type that only copies data that has been changed or made since the previous backup activity was conducted. An incremental backup approach exists used when the amount of data that has to be protected stands too voluminous to do a full backup of that data every day.

An incremental backup exists one in which successive copies of the data contain only the portion that has been modified since the preceding backup copy was made. When a full recovery is required, the restoration process would require the last full backup plus all the incremental backups until the point of restoration.

Hence, Incremental backup needs a small amount of space and exists considered to have an involved restoration process.

To learn more about Incremental backup refer to:

brainly.com/question/17330367

#SPJ4

6 0
2 years ago
An application with which you can perform calculations on numbers and work with other data
zhannawk [14.2K]
Microsoft Excel or another spreadsheet program.
6 0
3 years ago
Why is the len ( ) function useful when using a loop to iterate through a stack?
Marizza181 [45]

The len ( ) function will run with each iteration, printing the element number each time.

6 0
3 years ago
Course Aggregation Many times, departments are only interested with how students have done in courses relative to a specific maj
nadezda [96]

Answer:

def course_grader(student_to_grades, course_prefix):

   student_grades = dict()

   for key, value in student_to_grades.items():

       grade_score = 0

       for course,grade in value.items():  

           if course_prefix == course:  

               grade_score += grade

                student_grades[key] = grade_score / len(value.keys())

   return student_grades

Explanation:

The course_grader function is a python program that accepts two arguments, the student dictionary and the course prefix. The function returns a dictionary of the student id as the key and the average grade of the student as the value.

8 0
2 years ago
Other questions:
  • Which strategy are you using when you only read the title, section headings, and captions?
    12·2 answers
  • Optimally, the __________ guides investment decisions and decisions on how ISs will be developed, acquired, and/or implemented.
    6·1 answer
  • What is the use of form in HTML​
    12·1 answer
  • What is are motor vehicle emissions?
    8·1 answer
  • I'm confused. Are , , and elements or nodes? What exactly defines nodes? What defines elements?
    13·1 answer
  • An ip address in the address range 169.254.x.y, used by a computer when it cannot successfully lease an ip address from a dhcp s
    6·1 answer
  • Match the ernerging technologies to their descriptions.
    14·1 answer
  • A small startup company has hired you to harden their new network. Because funds are limited, you have decided to implement a un
    8·1 answer
  • What what do these two parts of the lift do ​
    14·1 answer
  • Is TCP really more secure than other L4 protocols by default?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!