Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago