-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummatrix.java
More file actions
49 lines (38 loc) · 808 Bytes
/
summatrix.java
File metadata and controls
49 lines (38 loc) · 808 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.util.Scanner;
public class matrix{
public static void main(String arg[]) {
Scanner max = new Scanner(System.in);
int arr[][]=new int[3][3];
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.println("Enter the value of each Element\n");
arr[i][j]=max.nextInt();
}
}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(arr[i][j]+"\t");
}
System.out.print("\n\n");
}
int count =0;
int count1=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(i==j){
count=count + arr[i][j];
}
if(i==3-j-1){
count1=count1+arr[i][j];
}
}
}
System.out.println(count);
System.out.println(count1);
}}