-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumber89.java
More file actions
50 lines (49 loc) · 875 Bytes
/
Number89.java
File metadata and controls
50 lines (49 loc) · 875 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
50
import java.util.*;
public class Number89 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n,i,j,s,s1,k=0;
System.out.println("Enter the order of matrix");
n=sc.nextInt();
int a[][]=new int[n][n];
System.out.println("Enter "+(n*n)+" numbers");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=sc.nextInt();
}
}
int b[]=new int[(2*n)+2];
for(i=0;i<n;i++)
{
s=0;
s1=0;
for(j=0;j<n;j++)
{
s=s+a[i][j];
s1=s1+a[j][i];
}
b[k++]=s;
b[k++]=s1;
}
s=0;
s1=0;
for(i=0;i<n;i++)
{
s=s+a[i][i];
s1=s1+a[i][n-i-1];
}
b[k++]=s;
b[k++]=s1;
for(i=0;i<b.length-1;i++)
{
if(b[i]!=b[i+1])
break;
}
if(i==b.length-1)
System.out.println("Magic Square");
else
System.out.println("Not Magic Square");
}
}