mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 06:23:08 +08:00
@ -2,8 +2,9 @@ package com.thealgorithms.maths;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/*A magic square of order n is an arrangement of distinct n^2 integers,in a square, such that the n numbers in all
|
||||
rows, all columns, and both diagonals sum to the same constant. A magic square contains the integers from 1 to n^2.*/
|
||||
/*A magic square of order n is an arrangement of distinct n^2 integers,in a square, such that the n
|
||||
numbers in all rows, all columns, and both diagonals sum to the same constant. A magic square
|
||||
contains the integers from 1 to n^2.*/
|
||||
public class MagicSquare {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -22,10 +23,7 @@ public class MagicSquare {
|
||||
magic_square[row_num][col_num] = 1;
|
||||
|
||||
for (int i = 2; i <= num * num; i++) {
|
||||
if (
|
||||
magic_square[(row_num - 1 + num) % num][(col_num + 1) % num] ==
|
||||
0
|
||||
) {
|
||||
if (magic_square[(row_num - 1 + num) % num][(col_num + 1) % num] == 0) {
|
||||
row_num = (row_num - 1 + num) % num;
|
||||
col_num = (col_num + 1) % num;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user