Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

12.1 Can this be answered in java please 74 3 19 23 21 62 Array iNums Paper and

ID: 3777932 • Letter: 1

Question

12.1 Can this be answered in java please

74

3

19

23

21

62

Array iNums

Paper and Pencil Exercises

Write a statement that populates a two-dimensional array named iNums with the values above using shortcut notation. Use the values above.

Write a statement to display the value stored in iNums[0][0].

Write a statement to display the value stored in iNums[2][2].

Write the statements needed to display the number of rows and columns in the array as follows:

Rows: 2
Cols: 3

Write a statement that adds 5 to the value stored in iNums[1][2].

Sum the second value in the first row and the last value in the second row to the variable iSum.

Sum all values in the second row to the variable, iRowTotal.

Sum the values in the second column to the variable iColTotal.

74

3

19

23

21

62

Explanation / Answer

Paper and Pencil Exercises

1) Write a statement that populates a two-dimensional array named iNums with the values above using shortcut notation. Use the values above.
   Using shortcut notation
       int nums[][]={{74, 3, 19}, {23, 21, 62}};// creates an array of row: 2 and col: 3
      
2)   Write a statement to display the value stored in iNums[0][0].
   System.out.println(iNums[0][0]);// prints 74

3)   Write a statement to display the value stored in iNums[2][2].
       Throws java.lang.ArrayIndexOutOfBoundsException exception since the array index starts with 0 and there are only 2 rows i.e index can be max of 1

4)   Write the statements needed to display the number of rows and columns in the array as follows:
      
       System.out.println("Row: "+iNums.length);
       System.out.println("Cols: "+iNums[0].length);

5)   Write a statement that adds 5 to the value stored in iNums[1][2].
       iNums[1][2]=iNums[1][2]+5;

6)   Sum the second value in the first row and the last value in the second row to the variable iSum.

   int iSum=iNums[0][1]+iNums[1][2];
  
7) Sum all values in the second row to the variable, iRowTotal.
      
   int iRowTotal=0;
       for(int i=1;i<iNums.length;i++){
           for (int j = 0; j < iNums[i].length; j++) {
               iRowTotal=iRowTotal+iNums[i][j];
           }
       }
   System.out.println("iRowTotal:"+iRowTotal);
  
8) Sum the values in the second column to the variable iColTotal.
  
   int iColTotal=0;
       for(int i=0;i<iNums.length;i++){
           for (int j = 1; j <=1; j++) {
               iColTotal=iColTotal+iNums[i][j];
           }
       }
   System.out.println("iColTotal:"+iColTotal);

--------------------------------------------

Note: Feel free to ask any question. God bless you!!

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote