Question

Which of the following segments of code will display the first row of a two dimensional...

Which of the following segments of code will display the first row of a two dimensional array?

-for (int i = 0; i < anArray.GetLength(1); i++)
Console.Write(anArray[0, i] + “\t”);
- for (int i = 0; i < anArray.GetLength(0); i++)
Console.Write(anArray[0, i] + “\t”);
-for (int i = 0; i < anArray.GetLength(0); i++)
Console.Write(anArray[i, 0] + “\t”);
- for (int i = 0; i < anArray.GetLength(1); i++)
Console.Write(anArray[i, 0] + “\t”);
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solutin:

Following segment of code will display the first row of a two dimensional array anArray.

for (int i = 0; i < anArray.GetLength(1); i++)
Console.Write(anArray[0, i] + “\t”);

Explanation:

GetLength(i) returns the number of elements in the ith dimension. So for a two dimensional array GetLength(0) returns the number of rows and GetLength(1) returns the number of columns.

anArray[0,i] will print the first row elements , as i will vary from column 0 till the number of columns specified by GetLength(1).

Add a comment
Know the answer?
Add Answer to:
Which of the following segments of code will display the first row of a two dimensional...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assume arr2 is declared as a two-dimensional array of integers. Which of the following segments of...

    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? int sum = 0; for(int j = 0; j < arr2.length; j++) {    for(int k = 0; k < arr2[j].length; k++)    {       sum += arr2[k][j];    } } 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];    }...

  • A two-dimensional square array of integers is a Latin square if the following conditions are true. The first row has no duplicate values. All values in the first row of the square appear in each row...

    A two-dimensional square array of integers is a Latin square if the following conditions are true. The first row has no duplicate values. All values in the first row of the square appear in each row of the square. All values in the first row of the square appear in each column of the square. Examples of Latin Squares 10 30 200 0 20 30 10 30 0 10 20 20 10 0 30 Examples that are NOT Latin Squares...

  • QUESTION 1 Using the following declarations and a member of the Array class, int [ ]...

    QUESTION 1 Using the following declarations and a member of the Array class, int [ ] bArray = new int [10]; int location; Using a method in the Array class, write a statement that would change the order of the elements in the bArray array. The contents of the first cell should hold what was in the last cell. The second cell should hold what was in the next to last cell. __________________________ HINT: You must write the full statement...

  • Q is a TWO-DIMENSIONAL array of 3 rows and 3 columns. Write the statement to DISPLAY...

    Q is a TWO-DIMENSIONAL array of 3 rows and 3 columns. Write the statement to DISPLAY the value of the middle element of array Q. NOTE: Do not skip lines. Do not print an output label. ------------------------------- (T/F) The following statements store 75 into the first array element. int Score[10]; Score [1] = 75; ------------------------------- kindly help urgently

  • java To access the element at row i and column / of a two-dimensional array named...

    java To access the element at row i and column / of a two-dimensional array named grades, we would use which of the following? O grades01 O grades(1) grades grades[J] QUESTION 6 Which of the following are errors in this syntax declaring a two-dimensional array? datatype [4) (0] [3] arrayNam: The brackets must be empty There must be two brackets, not three The syntax must end in a semicolon, not a colon All of these are errors in the syntax

  • in the missing code for the following program that initializes each variable with its row +...

    in the missing code for the following program that initializes each variable with its row + column. void init(int all [3], int i, int c) II initialize a 3x3 array: row & column int i, j; for (i=0; for(j=0; a[i] [5] = i+j; int main() { int a [3] [3); init return 1; _); // call init

  • I am unsure how to add the following methods onto this code?? please help - rowValuesIncrease(int[][]...

    I am unsure how to add the following methods onto this code?? please help - rowValuesIncrease(int[][] t) A method that returns true if from left to right in any row, the integers are increasing, otherwise false. - columnValuesIncrease(int[][] t) A method that returns true if from top to bottom in any column, the integers are increasing, otherwise false. - isSetOf1toN(int[][] t) A method that returns true if the set of integers used is {1, 2, . . . , n}...

  • Can someone explain this code with comments I am supposed to dispay an array an add...

    Can someone explain this code with comments I am supposed to dispay an array an add each columns and add each row An application uses a two-dimensional array declared as follows: int[][] days = new int[29][5]; a. Write code that sums each row in the array and displays the results. b. Write code that sums each column in the array and displays the results. class TwoDimensionalArrayDemo { public static void main( String[] arg ) { int[][] days = new int[29][5];...

  • (10 pts) Declare a two-dimensional int array of size 3 x 4 (row x column) and...

    (10 pts) Declare a two-dimensional int array of size 3 x 4 (row x column) and initialize the element array[0][1] to 1 and all other elements to zeros. Use a shortest possible statement.

  • 7) Implement a two-dimensional grid with a one dimensional array. a) Implement an empty array of...

    7) Implement a two-dimensional grid with a one dimensional array. a) Implement an empty array of four integers. D) Request four integers from the console and store them into the array. In this array, the index represents a column, the value a row. c) Implement an output function to display the array as a two-dimensional grid of X's and dots where x is an array coordinate. Example output (input is bold and italicized) : Enter 4. row values (from 0...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT