Professional Documents
Culture Documents
CC104 Prelim Project
CC104 Prelim Project
Prelim Project
PALOMA, RONA JEAN R.
BSIT-1B
Write a program that will print a magic square in up-left algorithm.
Sample Output:
Enter N: 3
6 1 8
7 5 3
2 9 4
Note: The program will prompt a message if the value inputted for N is even.
Answer:
import java.util.Scanner;
int n = input.nextInt();
if (n % 2 == 0) {
return;
int row = 0;
int col = n / 2;
magicSquare[row][col] = I;
if (I % n == 0) {
row++;
} else {
if (row == 0) {
row = n – 1;
CC 104
Prelim Project
} else {
row--;
if (col == 0) {
col = n – 1;
} else {
col--;
System.out.println(“Magic Square:”);
System.out.print(magicSquare[i][j] + “\t”);
System.out.println();