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]
2 years ago
11

Given an array as follows

Computers and Technology
1 answer:
slava [35]2 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
What is the next line? &gt;&gt;&gt; tupleB = (5, 7, 5, 10, 2, 7) &gt;&gt;&gt; tupleB.count(7) 1 0 5 2
dybincka [34]

Answer:

The right answer is option 4: 2

Explanation:

Lists are used in Python to store elements of same or different data types.

Different functions are used in Python on List. One of them is count.

Count is used to count how many times a specific value occurs in a list.

The syntax for count is:

listname.count(value)

In the given code,

The output will be 2

Hence,

The right answer is option 4: 2

3 0
2 years ago
What is the current through R1?
patriot [66]
I = V/R. So the answer is 9/200 = 0.045A = 45mA which is B
8 0
2 years ago
How do I add my bestie on brainy? /??!!! ​
ziro4ka [17]

Answer:

You have to remember their name on here

Explanation:

If u dont you cant talk to them again

3 0
2 years ago
A desperate employee calls because she has accidentally deleted crucial files from her hard drive and can’t retrieve them from t
konstantin123 [22]

Answer: The file may have been lost due to incompatibility with the operating system, inadequate space on the hard disk drive, or through corruption of the recycle bin.

However, I will have to ask her the following questions:

- name of operating system she is utilizing,

- the time of deletion of files,

- the kind or extension of the deleted file,

- the model number of the computer,

- the size of files created after the deletion of files.

Also, sometimes, deleted files could be irretrievable due to security breeches. The employee may not have the required access to the crucial file but accidentally stumble upon it.

After all of these have been determined, then the error is fixed, and the document/file is restored, and becomes accessible to the employee.

6 0
2 years ago
What can be found in the computer tower
8_murik_8 [283]
There are several things.
Some which include of
<span>Hard Disk Drive (HDD)
</span><span>Processor (CPU)
</span><span>Graphics card
</span>and
<span>Memory (RAM)</span>
8 0
3 years ago
Other questions:
  • Design the below using an array// Sunrise Freight charges standard// per-pound shipping prices to the five states they serve// –
    6·1 answer
  • Theâ ______ is a large worldwide collection of networks that use a common protocol to communicate with one another.
    5·1 answer
  • It's time for you to schedule a dental checkup. The responsible thing to do is to ___
    11·1 answer
  • You use a ____ following the closing brace of an array initialization list.
    12·2 answers
  • The scene of a human sitting at a computer terminal, responding to stimuli flashed on the computer screen, would most likely be
    7·1 answer
  • The World Wide Web Click on a Description on the left, then click the Term that best fits the Description. Description Technolog
    5·1 answer
  • Plz can someone tell me the answers ?
    13·2 answers
  • How do Computer Scientists use Binary Code?
    14·1 answer
  • I need a Python program that will read a data file, perform an analysis, and write the results to a separate file with a .txt ex
    15·2 answers
  • Programs for embedded devices are often written in assembly language. Some embedded processors have limited instructions, like M
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!