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
MAXImum [283]
3 years ago
6

Assume arr2 is declared as a two-dimensional array of integers. Which of the following segments of code successfully calculates

the sum of all elements arr2?
A.int sum = 0;for(int j = 0; j < arr2.length; j++){ for(int k = 0; k < arr2[j].length; k++) { sum += arr2[k][j]; }}
B.
int sum = 0;for(int j = arr2.length − 1; j >= 0; j−−){ for(int k = 0; k < arr2[j].length; k++) { sum += arr2[j][k]; }}
C.
int sum = 0;for(int[] m : arr2){ for(int n : m) { sum += n; }}
Computers and Technology
1 answer:
Delvig [45]3 years ago
3 0

Answer:

int sum = 0;for(int[] m : arr2){ for(int n : m) { sum += n; }}

Explanation:

Option A is wrong because it will throw an ArrayIndexOutOfBoundsException during the last iteration of the first and second loop.

the number of accessible element in the first dimension of arr2 is from 0 to arr2.length-1 but the loop specify 0 to arr2.length which will be the first cause of the error

while that of the second dimension specify 0 to arr2[j].length  instead of 0 to arr2[j].length-1

Option B is also wrong because the expression j-- will decrement the value of j instead of incrementing it and the second dimension specify 0 to arr2[j].length  instead of 0 to arr2[j].length-1 which will also cause an ArrayIndexOutOfBoundsException.

Option C will successfully calculates the sum of all elements arr2.

You might be interested in
One reason it is important to write code that is readable is that
kramer

Answer:

The answer is D:)

Explanation:

D) it makes it easier to follow when revisions or updates are called for.

8 0
3 years ago
Read 2 more answers
Which of the following can a cell contain?
Ksju [112]
The answer is choice D-All of these :)
8 0
2 years ago
Read 2 more answers
We can harden a host by: a. Limiting physical access to it b. Turning off unnecessary services c. Installing patches d. All of t
Rina8888 [55]

Answer:

D

Explanation:

All three of A, B and C are required to harden a host. Thus, All of the above makes the best option.

Hardening simply refers to making your data impossible to be penetrated. More like bulletproof.

To do this, ensure measures like

- Regular Program cleanup

- Patches management

- service pack installation

- service or usage policies

...among others.

Cheers

3 0
2 years ago
Why green office became popular among businesses? ​
Tanzania [10]

Answer:

Going green has several other benefits for companies. These include tax credits and incentives, improved efficiency, healthier workplaces, and cost savings – for instance by printing less, turning lights off in unused rooms and refilling ink cartridges. Reusing items also reduces waste from plastic packaging.

Explanation:

3 0
2 years ago
Read 2 more answers
Arrange the steps for conflict resolution in proper sequence.
VashaNatasha [74]

1.Clarify what the disagreement is

2. Establish a common goal for both parties

3. Discuss ways to meet the common goal 

4. Determine the barriers to the common goal

5. Agree on the best way to resolve the conflict

6. Acknowledge the agreed upon solution and determine the responsibilities each part has in the resolution 

8 0
3 years ago
Read 2 more answers
Other questions:
  • Examples of algorithm
    5·1 answer
  • Explain how the principles underlying agile methods lead to accelerated development and deployment of software.
    6·1 answer
  • Is it just me or is brainly not working right now? I am trying to add friends and it won't let me!
    5·2 answers
  • what is the gpa(grade point average) you need to have or you get kicked out of robotics for middle school?
    7·2 answers
  • Advantages of purchasing a software package over developing software in-house include all of the following except ____. Group of
    13·1 answer
  • Create a loop that will output all the multiples of 5 that are greater than zero and less than 60 (do not include 60). 5, 10, 15
    10·1 answer
  • What is a parameter variable?
    8·1 answer
  • Word processing software, spreadsheet software, database software, and presentation software are examples of what category of co
    13·1 answer
  • Which line correctly starts the definition of a class named "team"?
    7·1 answer
  • Do you think Mortal Combat is cool?
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!