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
The ____ method returns an integer that represents the location of the substring within the string.
enot [183]

Insert Method

it is used to returns an integer that speaks to the area of the substring inside the string.

5 0
3 years ago
Which statement is true? Select 3 options.
irina1246 [14]

Answer:

The statements which are true are;

  • A user-defined data type can include other user-defined data types
  • A user-defined data type is defined using a class
  • A user-defined data type can include a list

Explanation:

A user-defined data type (UDT) is a datatype that is defined and derived by the use of the datatypes which preexist including existing user-defined datatypes and the built-in datatypes

It is therefore true that a user-defined data type can include other user-defined data types

A class is a user-defined data type that contains both its member data and member functions, that can be used when an instance of the class is first created

Therefore, a user-defined data type is defined using a class

In a user-defined data type, a variable has actual data within it which can include an array or list

Therefore a user-defined data type can include a list.

3 0
2 years ago
Read 2 more answers
List 5 items you should keep in mind when developing an app:
Mrac [35]

Answer:

  1. Agree on aims concerning the application.
  2. Read your end users.
  3. Take your IT partners toward the conversations in the beginning.
  4. Program for various announcements.
  5. Choose the technology which you know and will be able to continue.

Explanation:

You should always keep the above five points while developing an app. You should keep your goals in mind that what kind of app you are going to develop and you are taking surveys from end users that what they want after some time in different cycles. Your team should discuss your project time by time about the progress of an app. Your project should be a long term and should almost cover all kind of users.



6 0
3 years ago
Write a function called countstuff () that takes as a parameter a character array, and returns an int. The prototype must be:
PSYCHO15rus [73]

Answer:

Please kindly go to the explanation part.

Explanation:

The required function is written in Raw code below.

Function:

#include<stdio.h>

#include<ctype.h> //including required libraries

int countstuff(char s[]){ //Function countstuff

int cntUp=0,cntLow =0,cntDigits = 0,i=0,value; //declaring required variables

for(i=0;s[i]!='\0';i++){ //loop to iterate over the characters of string

if(isupper(s[i])){

cntUp++; //incrementing count of uppercase if it is uppercase character

}

else if(islower(s[i])){

cntLow++; //incrementing count of lowercase if it is lowercase character

}

else if(isdigit(s[i])){

cntDigits++; //incrementing count of digits if it is digit

}

}

value = cntUp*1000000 + cntLow*1000 + cntDigits; //counting value using formula given in question

return value; //returning the value

}

void main(){

char string[1000]; //declaring required variables

int value;

printf("Enter a String:");

scanf("%[^\n]s",string); //taking string as input

value = countstuff(string); //calling function

printf("The Value is : %d\n",value); //printing result

}

5 0
2 years ago
How many generations of computers languages have there been since the middle of the 20th century
Molodets [167]
<span>There are 4 computer language generations. First is the first generation language or 1GL, second is the second-generation languages or the 2GL, next is the third-generation languages or the 3GL, and the last is fourth-generation languages or the 4GL.</span>
4 0
2 years ago
Read 2 more answers
Other questions:
  • What is the output of this code? import java.util.HashSet; class A { public static void main(String[ ] args) { HashSet set = new
    15·1 answer
  • What computer has best software
    5·1 answer
  • What does this say:<br> √ans
    6·2 answers
  • Produce definition in computer
    12·2 answers
  • Which one of these variables has an illegal name?
    11·1 answer
  • A relational database is different from a simple database because it has more than one _____.
    13·1 answer
  • Answer this question for points lol
    7·2 answers
  • Hurry im TIMED
    8·1 answer
  • Hiiiiiiiiiiiiiiiiii <br>i'm new here!!!​
    14·2 answers
  • Which of the following is not harmful to the computer?<br> a) Trojan<br> b) Rootkit<br> c)Malware
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!