Question: Using the code I already have I need help figuring out how to write the diag 2 for a magic square in JAVA. This is

Using the code I already have
I need help figuring out how to write the diag2 for a magic square in JAVA. This is the code I have so far.
import java.util.*;
import java.io.*;
public class Main {
static Scanner inp = new Scanner(System.in);
private int[][] square;
private boolean[] possible;
private int totalSqs;
private int magicConst;
private int numsquares;
public Main(int N){
if (N <=2){
System.out.print("Only give values >2!!");
System.exit(1);
}
square = new int [N][N]; // initialize with zeros by default
magicConst = this.findMagicConstant(N);
totalSqs = N*N;
possible = new boolean[totalSqs];
for(int i =0; i < totalSqs; i ++)
possible[i]= true;
numsquares =0;
}
public int findMagicConstant(int N){
int last_num = N*N;
int sum = last_num *(last_num +1)/2;
return sum/N;
}
public void fill(int row, int col){
if (validSquare()){
System.out.println("Done!!");
for(int[] rws: square){
System.out.println(Arrays.toString(rws));
}
}
if (row == square.length){
//System.out.println(this);
numsquares++;
return;
}
//System.out.println(totalSqs);
for(int i =0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!