Page 389 - CA_Blue( J )_Class10
P. 389
5 int i,j,m,n,s;
6 System.out.println("Enter number of rows : ");
7 m=sc.nextInt();
8 System.out.println("Enter number of columns : ");
9 n=sc.nextInt();
10 int ar[][]=new int[m][n];
11 for (i=0; i<m; i++)
12 { for(j=0;j<n;j++)
13 { System.out.print("Enter a number : ");
14 ar[i][j] =sc.nextInt();
15 }
16 }
17 for (i=0; i<m; i++)
18 { s=0;
19 for(j=0;j<n;j++)
20 { s=s+ar[i][j]; }
21 System.out.println("Sum of row "+ (i+1)+" : "+s);
22 }
23 }
24 }
You will get the following output:
Enter number of rows : 2
Enter number of columns : 2
Enter a number : 1
Enter a number : 2
Enter a number : 3
Enter a number : 4
Sum of row 1 : 3
Sum of row 2 : 7
To store the numbers in a 3 x 3 matrix and assign the Transposed matrix in another array and
Program 9
display it. Transpose means interchanging of the rows and columns.
1 import java.util.*;
2 class array_double_transpose
3 { public static void main()
4 { Scanner sc= new Scanner(System.in);
5 int i,j;
387
Arrays 387

