Page 342 - Cs_withBlue_J_C11_Flipbook
P. 342
Enter a number: 9
Array 1
11 44 66
55 77 99
88 44 55
Array 2
1 2 3
4 5 6
7 8 9
Array after multiplication
649 770 891
1056 1287 1518
649 836 1023
Program 13 Write a program in Java to store data in a matrix 4 × 4 and display the elements of the matrix
by replacing each element of the left diagonal with zero.
1 import java.util.*;
2 class diagonal
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 int i, j;
8 int ar[ ][ ]=new int[4][4];
9 for (i=0; i<4; i++)
10 {
11 for(j=0; j<4; j++)
12 {
13 System.out.print("Enter a number: ");
14 ar[i][j] =sc.nextInt();
15 }
16 }
17 System.out.println("4x4 matrix is");
18 for(i=0; i<4; i++)
19 {
20 for(j=0; j<4; j++)
21 {
340340 Touchpad Computer Science-XI

