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
A wet-carpet cleaner that carries it's own water supply has water pressure created by a.
QveST [7]
The correct answer of the given question above would be option D. A wet-carpet cleaner that carries it's own water supply has water pressure created by a MOTOR-DRIVE PUMP. T<span>his product is easy to use, strong, and highly durable. Hope this answers your question. Have a great day!</span>
8 0
3 years ago
Read 2 more answers
Create a base class named rectangle that contains lenght and width data members.
kumpel [21]

Answer:

class Rectangle:  

   

   def __init__(self, length, width):

       self.length = length

       self.width = width

       

   

   def area(self):

       area = self.length*self.width

       return area

   

   

class Box (Rectangle):

   

   def __init__(self, length, width, height):

       super().__init__(length, width)

       self.height = height

       

   def volume(self):

       volume = self.length * self.width * self.height

       return volume

   

   def area(self):

       area = 2*(self.length*self.width) + 2*(self.length*self.height) + 2*(self.width*self.height)

       return area

rec_1 = Rectangle(2,4)

box_1 = Box(2,2,6)

print(box_1.length)

print(box_1.area())

   

print(rec_1.length)

print(rec_1.area())

Explanation:

The programming language used is python.

class Rectangle

The class Rectangle is created with attributes length and width.

The class attributes are initialized using the __init__ constructor.

In the rectangle class, a method/function is declared to return the area of the rectangle.

class Box

This class is a child of rectangle and it inherits all its attributes and methods,

It has an additional attribute of depth and its constructor is used to initialize it.

The class contains a volume function, that returns the volume and an override function 'area()' that displaces the area from the parent class.

Finally, some instances of both classes are created.

4 0
3 years ago
Digital Sep <br> helps as reimagine outcomes true or false
iragen [17]

Answer:

true

Explanation:

mark me as brailyist pls

6 0
3 years ago
In 3–5 sentences, describe the unique challenges e-mail presents for business communications.
alina1380 [7]
One of the things that are a challenge, is that you have to get the correct puntuation, correct capitilization, because it's a buisness email. You ont want to mess a buisness email up. You also have to have no repating phrases and sentences. You can't be adding random words and saying "and" all the time. 
7 0
3 years ago
Read 2 more answers
Graded Assignments may be found at the end of each chapter of the required textbook under the title "Real-World Exercises". Each
mina [271]
Ok chapter 2 be done by 11:59
5 0
3 years ago
Other questions:
  • At the dsl local carrier's office, the __________ demultiplexes the data streams and converts them into digital data.
    10·1 answer
  • In an office there is a unisex bathroom with n toilets. The bathroom is open to both men and women, but it cannot be used by men
    14·1 answer
  • Which windows tools would you use to browse the files system on a hard drive?
    6·2 answers
  • Chemical reaction rates are proportional to a rate constant, k, which changes with temperature according to the Arrhenius equati
    14·1 answer
  • In terms of data storage and sharing, in what way, if any, do dropbox services differ from archiving services?
    8·1 answer
  • Which guideline should you use when downloading software from the Internet?
    15·1 answer
  • which of the following types of software is for organizing analyzing and storing data in a table A spreadsheet software B databa
    11·1 answer
  • A customer has a computer for a home business, but wants to have another computer as a web server. What would be the best soluti
    11·2 answers
  • When pointed over a text within a paragraph, the cursor takes the shape of a/an
    10·1 answer
  • The FCFS algorithm is particularly troublesome for ____________.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!