Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help figuring out how to write the diag 2 for a magic square in JAVA. This is the code I have so far.
I need help figuring out how to write the diag 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 ScannerSystemin;
private int square;
private boolean possible;
private int totalSqs;
private int magicConst;
private int numsquares;
public Mainint N
if N
System.out.printOnly give values ;
System.exit;
square new int NN; initialize with zeros by default
magicConst this.findMagicConstantN;
totalSqs NN;
possible new booleantotalSqs;
forint i ; i totalSqs; i
possiblei true;
numsquares ;
public int findMagicConstantint N
int lastnum NN;
int sum lastnum lastnum ;
return sumN;
public void fillint row, int col
if validSquare
System.out.printlnDone;
forint rws: square
System.out.printlnArraystoStringrws;
if row square.length
Systemout.printlnthis;
numsquares;
return;
Systemout.printlntotalSqs;
forint i ; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started