FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaProb/Magic_Square.java at main · Warlord27/JavaProb · GitHub
Warlord27
/
JavaProb
Public
Notifications
You must be signed in to change notification settings
Fork
9
Star
13
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaProb
/
Magic_Square.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (34 loc) · 1.1 KB
Breadcrumbs
JavaProb
/
Magic_Square.java
Copy path
File metadata and controls
39 lines (34 loc) · 1.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
util
.
Scanner
;
public
class
Magic_Square
{
public
static
void
main
(
String
[]
args
) {
Scanner
sc
=
new
Scanner
(
System
.
in
);
System
.
out
.
print
(
"Give the length of N: "
);
int
n
=
sc
.
nextInt
(),
M
[][] =
new
int
[
n
][
n
],
r
,
c
,
rs
=
0
,
ls
=
0
,
cols
=
0
,
rows
=
0
,
s1
=
0
;
for
(
r
=
0
;
r
<
n
;
r
++) {
for
(
c
=
0
;
c
<
n
;
c
++) {
System
.
out
.
println
(
"Enter number: "
);
M
[
r
][
c
] =
sc
.
nextInt
();
}
}
for
(
r
=
0
;
r
<
n
;
r
++) {
rs
+=
M
[
r
][
r
];
ls
+=
M
[
r
][
n
-
r
-
1
];
}
rows
=
cols
=
0
;
for
(
r
=
0
;
r
<
n
;
r
++) {
if
(
rows
==
s1
) {
rows
=
cols
=
0
;
for
(
c
=
0
;
c
<
n
;
c
++) {
cols
+=
M
[
r
][
c
];
rows
+=
M
[
c
][
r
];
}
if
(
cols
!=
rows
) {
System
.
out
.
println
(
"Not a magic square"
);
System
.
exit
(
0
);
}
}
}
if
((
rows
==
ls
) && (
ls
==
rs
) && (
rs
==
s1
))
System
.
out
.
println
(
"Magic Square"
);
}
}
Back
|
FazBrowse Home
|
New Git URL