Page 305 - Computer science 868 Class 12
P. 305
4. Using direct input from method
Program 15 Write a program to create a double-dimensional array of size n x m. Input the numbers in first
(n-1) × (m-1) cells. Find and place the sum of each row and each column in corresponding
cells of last column and last row respectively. Finally, display the array elements along with
the sum of rows and columns.
Sample Input : row = 3, col = 4
1 2 3
4 5 6
Sample Output
1 2 3 6
4 5 6 15
5 7 9 0
1 import java.util.*;
2 class row_col
3 {
4 public static void main(int row, int col)
5 {
6 Scanner sc= new Scanner(System.in);
7 int arr[][] = new int[row][col];
8 int i,j,rs,cs;
9 System.out.println("Enter array elements");
10 for ( i = 0; i < row-1; i++)
11 {
12 System.out.println("Enter Row "+ (i+1) + " :");
13 for ( j = 0; j < col-1; j++)
14 {
15 arr[i][j] = sc.nextInt();
16 }
17 }
18 System.out.println("Input Array:");
19 for ( i = 0; i < row; i++)
20 {
21 for ( j = 0; j < col; j++)
22 {
23 System.out.print(arr[i][j] + "\t");
24 }
303
Arrays 303

