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]
4 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]4 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
What is a file allocation table (FAT), andwhere is it found on a floppy disk?
Akimi4 [234]

Answer:

File Allocation Table(FAT):- It is a computer file system  design and it is widely used on many computers and most of the memory  cards. FAT file systems are  commonly found on flash memory cards,floppy disks, digital cameras,  and many other portable devices.

In floppy disks, the FAT has been standardized as ISO/IEC 9293 and ECMA-107.These include FAT12 and FAT16 only without any long filename support.

5 0
3 years ago
Blender is used by which video game team member?
prohojiy [21]

Answer:

The 2nd one

Explanation:

6 0
3 years ago
Write a constructor for BaseballPlayer. The constructor takes three int parameters: numHits, numRuns, and numRBIs storing the va
Monica [59]

Answer:

Following are the code to the given question:

public class BaseballPlayer//defining a class BaseballPlayer

{

BaseballPlayer(int numHits, int numRuns, int numRBIs)//defining a parameterized cons

{

}

}

Explanation:

Some of the data is missing, which is why the solution can be represented as follows:

In this code, a class BaseballPlayer is defined, and inside the class a parameterized constructor is defined that holds three integer variable "numHits, numRuns, and numRBIs".

5 0
3 years ago
¿por qué se debe seleccionar todo el texto de un documento de word?. ​
DedPeter [7]

Explanation:

La selección de texto también se conoce como resaltar texto. Se usa a menudo cuando se usa Microsoft Word para tareas como formatear, eliminar, mover o copiar texto



4 0
3 years ago
Assume that a bool variable isquadrilateral has been declared , and that an int variable , numberofsides has been declared and i
masya89 [10]
You should state the language you're using in these types of questions; here's an example in C++.

bool isQuad;
int sides;
std::cout << "How many sides does the shape have?";
std::cin >> sides;
if (sides == 4)
isQuad = true;
else
isQuad = false;
7 0
3 years ago
Other questions:
  • If you have cut or copied a set of information, which procedure will NOT work to paste it back into the worksheet?
    14·1 answer
  • How is a computer component, such as a network card, commonly marked for identification?
    13·1 answer
  • We can include following item(s) during configuration itemidentification:
    10·1 answer
  • Ask the user to input an integer. Print out the next three consecutive numbers.
    14·2 answers
  • Consider the following statement from the CS Principles course framework: The global distribution of computing resources raises
    12·1 answer
  • When would it be beneficial to make a copy of a document
    10·1 answer
  • Create java program for these 2 question
    15·1 answer
  • He is the person behind the development of electronic mail
    13·1 answer
  • List four tasks that humans perform frequently, but which may be difficult for a computerized agent to accomplish. Describe the
    9·1 answer
  • What is a zerø-day exploit? No go.ogle &gt;:(
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!