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

public class ArrayQuickCode { // create and output two-dimensional arrays public

ID: 3719733 • Letter: P

Question

public class ArrayQuickCode

{

   // create and output two-dimensional arrays

   public static void main( String[] args )

   {

      int[][] array1 = { { 1, 2, 3 }, { 6, 5 }, { 8 } };

      System.out.println( " Values in array1 by row are: " );

      int arrayTotal = outputArray( array1 );                     

      System.out.printf("Array-total = %d ", arrayTotal);

      

   } // end main

   // please Write your method here I want the output to be like the picture.

Example Output: Values in arrayl by row are: 1 2 3 6 Array-Total-25

Explanation / Answer

ArrayQuickCode.java

public class ArrayQuickCode

{

// create and output two-dimensional arrays

public static void main( String[] args )

{

int[][] array1 = { { 1, 2, 3 }, { 6, 5 }, { 8 } };

System.out.println( " Values in array1 by row are: " );

int arrayTotal = outputArray( array1 );

System.out.printf("Array-total = %d ", arrayTotal);

  

} // end main

// please Write your method here I want the output to be like the picture.

public static int outputArray(int a[][]) {

int sum= 0,total = 0;

for(int i=0;i<a.length;i++) {

sum = 0;

for(int j=0;j<a[i].length;j++){

sum+=a[i][j];

System.out.print(a[i][j]+" ");

}

total+=sum;

System.out.println(" = "+sum);

}

return total;

}

}

Output:


Values in array1 by row are:

1 2 3 = 6
6 5 = 11
8 = 8
Array-total = 25