Problem Description For this lab you will create a 2D Array
Solution
import java.util.Scanner;
 import java.util.Arrays;
class Lab11
 {
    public static void main (String[] args)
    {
        Scanner scan = new Scanner(System.in); //scanner object
        int rows;
        int cols;
        int rowsum;
       
        System.out.println(\"Enter the number of rows in the array\");
        rows = scan.nextInt();
       
        System.out.println(\"Enter the number of columns in the array\");
        cols = scan.nextInt();
       
       
        int[][] intArray = new int[rows][cols];
       
        for(int i=0; i<rows; i++) //input elements of array
        {
        for(int j=0; j<cols; j++)
        {
            System.out.println(\"Enter the next number\");
            intArray[i][j] = scan.nextInt();
        }
        }
       
        for(int i=0; i<rows; i++)
        {
        for(int j=0; j<cols; j++)
        {
            System.out.print(intArray[i][j] + \" \"); //display elements of array
           
        }
        System.out.println();
        }
       
       
        for(int i=0; i<rows; i++)
        {
            rowsum = 0; //initialize sum of row =0
        for(int j=0; j<cols; j++)
        {
            rowsum = rowsum + intArray[i][j]; //compute sum of elemnts of a row
           
        }
        System.out.println(\"Sum of row \"+ i +\" is : \"+rowsum);
        }
    }
 }
output:


