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
Whats a computer scientist.
Kazeer [188]

Answer:

computer scientist is a person who has acquired the knowledge of computer science, the study of the theoretical foundations of information and computation and their application.

4 0
3 years ago
Read 2 more answers
Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The fi
Travka [436]

Answer:

Explanation:

Since no programming language is stated, I'll use Microsoft Visual C# in answering this question.

// C# program sort an array in ascending order

using System;

class SortingArray {

int n; //number of array elements

int [] numbers; //Array declaration

public static void Main() {

n = Convert.ToInt32(Console.ReadLine());

numbers = new int[n];

for(int i = 0; i<n; I++)

{

numbers [n] = Convert.ToInt32(Console.ReadLine());

}

SortArray();

foreach(int value in numbers)

{

Console.Write(value + " ");

}

}

void SortArray()

{

int temp;

// traverse 0 to array length

for (int i = 0; i < numbers.Length - 1; i++)

// traverse i+1 to array length

for (int j = i + 1; j < numbers.Length; j++){

// compare array element with all next element

if (numbers[i] < numbers[j])

{

temp = numbers[i];

numbers[i] = numbers[j];

numbers[j] = temp;

}

}

}

5 0
3 years ago
The process of engineering design typically starts with what ?
klemol [59]

The process of engineering typically starts with brainstorming.
6 0
3 years ago
The Brinley website will not let me search for questions anymore. It says “Search all you want in-app” and then covers the quest
ira [324]

Answer: U can answer a few questions of other people’s questions then the question that was covered it unlocks after answering some questions and u will be able to see it or u could get the app too and it doesn’t block at all

Explanation:

4 0
3 years ago
What is one disadvantage people face without a checking account?
sveticcg [70]

Answer:

If they have a job that only pays with ckecks they won't be able to have their paycheck.

Explanation:

8 0
3 years ago
Other questions:
  • What is meant by backing up files through cloud computing?
    5·2 answers
  • You are the IT administrator for a small corporate network. Recently, you added a web server that runs services that need to be
    12·1 answer
  • Lisa is modifying a spreadsheet. Which view will allow Lisa to see how her changes will look when she prints the spreadsheet?
    13·2 answers
  • A hacker uses a valid IP address of an internal host, and then from an external system, the hacker attempts to establish a commu
    11·1 answer
  • 5. Which one of the following statements is true for spell checkers? A. Most spell checkers flag inappropriate word usage. B. A
    5·1 answer
  • Using Visio, create a Local Area Network (LAN) consisting of 12 computers, a switch, and three printers. The switch should be in
    11·1 answer
  • Coding 5 - Classes The Item class is defined for you. See the bottom of the file to see how we will run the code. Define a class
    13·1 answer
  • If you forget your privacy password what will you do if the ask this question what is the name of one of your teacher?​
    12·1 answer
  • Who is famous for his three laws of robotics?
    9·1 answer
  • When one loop appears inside another, the loop that contains the other loop is called the ____ loop. Group of answer choices ind
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!