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
Given the following code segment, how can you best describe its behavior? i ← 1 FOR EACH x IN list { REMOVE(list, i) random ← RA
garik1379 [7]

Answer:

Well, this code would box the whole body of an html document. by using the relative value for position, you are telling it to position relative to its normal position, which the top left corner is at (0,0). by using left: 50px, you are telling the box to set the left margin edge to 50px and by using top: 50px, you are telling it to set the top margin edge to 50px. by doing this shifting, the top left corner of the box, which is at (0,0) would be positioned at (50,50)

6 0
3 years ago
Write a function called is_present that takes in two parameters: an integer and a list of integers (NOTE that the first paramete
Agata [3.3K]

Answer:

The function in python is as follows

def is_present(num,list):

    stat = False

    if num in list:

         stat = True

       

    return bool(stat)

Explanation:

This defines the function

def is_present(num,list):

This initializes a boolean variable to false

    stat = False

If the integer number is present in the list

    if num in list:

This boolean variable is updated to true

         stat = True

This returns true or false        

    return bool(stat)

7 0
3 years ago
Jeremy has been asked by his manager to begin drafting a report on last year’s sales figures. When he’s midway through the repor
tekilochka [14]
He has demonstrated adaptability.
6 0
3 years ago
Read 2 more answers
He memory unit of a computer has 2 20 words. The computer has instruction format with four fields; an operation code field, a mo
Mashutka [201]

Answer:

Opcode = 3

Mode =2

RegisterRegister =7

AR = 20

Explanation:

a) Number of addressing modes = 4 = 22 , So it needs 2 bits for 4 values

Number of registers = 65 = 1000001 in binary , So it needs 7 bits

AR = 20

Bits left for opcode = 32 -(2+7+20) = 3

3 0
3 years ago
To transfer files to your company's internal network from home, you use FTP. The administrator has recently implemented a firewa
Aleonysh [2.5K]

Answer:

Ports 20 and 21

Explanation:

For the FTP to work, there are two parts that are required; the command and the data.  These two parts are sent on the two ports 21 and 20 respectively.  If the firewall is indeed blocking connections on ports 21 and 20, then your FTP will not work.

Hence, you need to open ports 20 and 21 to allow FTP to remain functional.

Cheers.

6 0
3 years ago
Other questions:
  • What did early computers use to store each bit?
    12·2 answers
  • The function below takes two parameters: a string parameter: CSV_string and an integer index. This string parameter will hold a
    14·1 answer
  • Assume that a is an array of two or more integers, and that b and c are integers.
    13·1 answer
  • During detachment, _____.
    12·2 answers
  • Which peripheral device is used to record sound?
    14·2 answers
  • Devices that allow for the retention of data when your computer has been shutdown
    10·1 answer
  • Krya needs help deciding which colors she should use on her web page. What can she use to help her decide.
    11·1 answer
  • Decomposition is
    5·1 answer
  • If you want to share information with individuals who are internal to your organization, which type of network would you want to
    6·1 answer
  • Is majority intent determined by how many times the same type of result is shown on the search engine result page?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!