Page 334 - Cs_withBlue_J_C11_Flipbook
P. 334
44 for(j=0; j<3; j++)
45 {
46 System.out.print(a[i][j]+ " ");
47 }
48 System.out.println();
49 }
50 }
51 }
The output of the preceding program is as follows:
Enter a number: 0 , 0 : 12
Enter a number: 0 , 1 : 36
Enter a number: 0 , 2 : 17
Enter a number: 1 , 0 : 25
Enter a number: 1 , 1 : 85
Enter a number: 1 , 2 : 96
Enter a number: 2 , 0 : 45
Enter a number: 2 , 1 : 25
Enter a number: 2 , 2 : 11
The array before sorting:
12 36 12
25 85 96
45 25 11
The array after sorting:
12 17 36
25 85 96
11 25 45
Program 10 Write a program to accept number into a 3 × 4 matrix. Display the original array. Then calculate
and display each row total.
1 class rowwise_total
2 {
3 public static void main()
4 {
5 int a[ ][ ] = {{1,3,6,8}, {1,2,3,4}, {6,4,3,8}};
6 int i, j, sum=0;
7 for(i = 0; i<3; i++)
8 {
9 for(j = 0; j<4; j++)
332332 Touchpad Computer Science-XI

