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
Suppose a process in Host C has a UDP socket with port number 6789. Suppose both Host A and Host B each send a UDP segment to Ho
Ann [662]

Answer:

Yes, both of these segments (A and B) will be directed to the same socket at Host C .

Explanation:

Suppose both Host A and Host B each send a UDP segment to Host C with destination port number 6789, surely , both of these segments will be directed to the same socket at Host C .

Reason being that,  the operating system will provide the process with the IP details to distinguish between the individual segments arriving at host C- for each of the segments (A and B) recieved at Host C.

5 0
3 years ago
How to write a program to draw 1000 random points on a frame in python language for coding?
harina [27]

Answer:

You could generate random numbers between the pixel amount of the height and width than place the dots at those random points

Explanation:

Do you need the code or can you make it using my "headstart"

8 0
3 years ago
What kind of server connects a remote system through the internet to local serial ports using tcp/ip?
zaharov [31]
A proxy server. A system requests information from the internet, and that traffic is routed through the proxy server before arriving to the requesting system.

This is why proxy servers are used for hiding identity and being more secure, as internet traffic would show the IP address of the proxy server, and not the requesting system, though this often depends on the type of proxy server, as some proxy server's main objective isn't anonymousity, but rather efficiency.
4 0
3 years ago
or each array created, the name of the array becomes the name of the pointer constant created by the compiler for the array, and
JulijaS [17]

Answer:

The answer is "Starting address"

Explanation:

Arrays are a type of data structure that can store a fixed size successive assortment of components of a similar kind. An Array is used to store an assortment of data, yet it is regularly more valuable to consider a cluster an assortment of factors of a similar sort.

Rather than proclaiming singular factors, for example, number0, number1, ..., and number99, you declare one Array variable, for example, numbers and use numbers[0], numbers[1], and ..., numbers[99] to speak to singular factors. A particular component in a cluster is gotten to by a list.

All Arrays comprise of bordering memory areas. The most minimal address compares to the first element and the most highest address to the last element.

4 0
3 years ago
What are they ethical issues with Drones?
guajiro [1.7K]
They may invade privacy rights of air space and be used for other unintended acts such a bombings and espionage
4 0
3 years ago
Other questions:
  • A compound document contains _______ from different applications.
    12·2 answers
  • A model release can be either oral or written down. true or false
    11·2 answers
  • What are some examples of lighter-than-air vehicles?
    10·1 answer
  • Design two subclasses of Employee…SalariedEmployee and HourlyEmployee. A salaried employee has an annual salary attribute. An ho
    12·1 answer
  • Technician A says that it's a good idea to perform a test drive before attempting repairs. Technician B says that it's a good id
    9·2 answers
  • Match the keyboard shortcuts to the function they perform
    10·1 answer
  • Fill in the blanks in the SQL statement below that will list the invoice number, invoice total and credit which is the total sum
    14·1 answer
  • 3. Which property provided the labels in the list below?
    9·1 answer
  • What are the main security weaknesses of coaxial cable, twisted pair cable, and fiber optic cable? How might the router itself b
    8·1 answer
  • PLEASE PLEASE PLEASE PLEASE help me Im completly lost will give brainliest and 50 points
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!