Java 以null&;输出结束;不';跑不动
尝试为我的Java类创建一个魔方游戏。我的第一次检查得到了以下代码:Java 以null&;输出结束;不';跑不动,java,arrays,Java,Arrays,尝试为我的Java类创建一个魔方游戏。我的第一次检查得到了以下代码: import java.util.Arrays; import java.util.Scanner; public class square { static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { String mainMenuUser = null; while(main
import java.util.Arrays;
import java.util.Scanner;
public class square {
static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
String mainMenuUser = null;
while(mainMenuUser != "quit"){
System.out.println();
System.out.println(" Welcome to Magic Square! ");
System.out.println("--------------------------");
System.out.println("Type any of the following:");
System.out.println("--------------------------");
System.out.println("Rules (Displays Rules)");
System.out.println("Play (Starts The Game)");
System.out.println("Quit (Quits The Game)");
System.out.println("--------------------------");
System.out.print("Your Choice: ");
mainMenuUser = scanner.next();
switch(mainMenuUser.toLowerCase()){
case "rules":
rules();
break;
case "play":
play(null);
break;
case "quit":
break;
default:
System.out.println("You Typed something wrong.");
break;
}
}
}
public static void rules(){
System.out.println("The Rules Are: ");
System.out.println("1: All numbers must be different");
System.out.println(" It will tell you if you have duplicates.");
System.out.println("2: All numbers must add up to be the same Left to right");
System.out.println("3: All numbers must add up to be the same Top to Bottom");
System.out.println("4: All numbers must add up to be the same Diagonal Top left to Bottom Right");
System.out.println("4.A: All numbers must add up to be the same Diagonal Top Right to Bottom Left");
}
public static void play(int[] rowTotalsLR){
int userGridSize;
int tempMultiply;
System.out.println("Please Enter a number for the size of the grid.");
System.out.println("This number will be squared");
userGridSize = scanner.nextInt();
tempMultiply = userGridSize * userGridSize;
System.out.println("Your Grid Size Will Be: " + tempMultiply);
takeInGridNums(userGridSize, rowTotalsLR);
}
public static void takeInGridNums(int userGridSize, int[] rowTotalsLR){
int gridRows = 0, gridColumns = 0;
int[][] gridNums = new int[userGridSize][userGridSize];
int tempSize = gridNums.length;
int tempSizeFull = tempSize * tempSize;
for(int temp = 0; temp != tempSizeFull; temp++){
if(gridColumns == gridNums.length){gridRows++; gridColumns = 0;}
System.out.println("Please Eneter A number for Grid Position: " + gridRows + " , " + gridColumns);
gridNums[gridRows][gridColumns] = scanner.nextInt();
gridColumns++;
}
leftToRight(tempSizeFull, gridNums, tempSizeFull);
topToBottom(tempSizeFull, gridNums, tempSizeFull);
diagonalLeftToRight(userGridSize, gridNums, tempSizeFull);
diagonalRightToLeft(userGridSize, gridNums, tempSizeFull);
outputResultsOfGame(tempSizeFull, gridNums, rowTotalsLR, null, tempSizeFull, tempSizeFull, tempSizeFull, null, null);
}
public static void leftToRight(int userGridSize, int[][] gridNums, int tempSizeFull){
int tempGridColumns = 0, totalLeftToRight = 0, tempPoint, tempTotal = 0, tempGridRows = 0;
int[] rowTotalsLR = new int[userGridSize];
for(int temp = 0; temp != tempSizeFull; temp++){
if(tempGridColumns == gridNums.length){
rowTotalsLR[tempGridRows] = totalLeftToRight;
tempGridRows++;
tempGridColumns = 0;
tempTotal = 0;
totalLeftToRight = 0;
}
tempPoint = gridNums[tempGridRows][tempGridColumns];
totalLeftToRight = tempTotal + tempPoint;
tempTotal = totalLeftToRight;
tempGridColumns++;
}
}
public static void topToBottom(int userGridSize, int[][] gridNums, int tempSizeFull){
int tempGridColumns = 0, totalRightToLeft = 0, tempPoint = 0, tempTotal = 0, tempGridRows = 0;
int[] rowTotalsRL = new int[userGridSize];
for(int temp = 0; temp != tempSizeFull; temp++){
if(tempGridRows == gridNums.length){
rowTotalsRL[tempGridRows] = totalRightToLeft;
tempGridColumns++;
tempGridRows = 0;
tempTotal = 0;
totalRightToLeft = 0;
}
tempPoint = gridNums[tempGridRows][tempGridColumns];
totalRightToLeft = tempTotal + tempPoint;
tempTotal = totalRightToLeft;
tempGridRows++;
}
}
public static void diagonalLeftToRight(int userGridSize, int[][] gridNums, int tempSizeFull){
int totalDagLeftToRight = 0, tempPoint = 0, tempTotal = 0;
int[] totalsDagLR = new int[userGridSize];
for(int temp = 0; temp < tempSizeFull; temp++){
//for(int temp = 0; temp != gridNums.length; temp++){
if(temp == gridNums.length){break;}
tempPoint = gridNums[temp][temp];
totalDagLeftToRight = tempTotal + tempPoint;
tempTotal = totalDagLeftToRight;
totalsDagLR[temp] = tempTotal;
}
}
public static void diagonalRightToLeft(int userGridSize, int[][] gridNums, int tempSizeFull){
int totalDagLeftToRight = 0, tempPoint = 0, tempTotal = 0, tempUp = 0, tempDown = gridNums.length-1;
int[] totalsDagRL = new int[userGridSize];
for(int temp = 0; temp != gridNums.length; temp++){
tempPoint = gridNums[tempUp][tempDown];
totalDagLeftToRight = tempTotal + tempPoint;
tempTotal = totalDagLeftToRight;
totalsDagRL[temp] = tempTotal;
}
}
public static void outputResultsOfGame(int userGridSize, int[][] gridNums, int[] rowTotalsLR, int[] rowTotalsRL, int gridRows, int gridColumns, int tempSizeFull, int[] totalsDagLR, long[] totalsDagRL){
System.out.println("Your Numbers Entered Were: ");
System.out.println(Arrays.deepToString(gridNums));
System.out.println("The Totals of the Rows Are: ");
System.out.println(Arrays.toString(rowTotalsLR));
System.out.println("The Total of the Columns Are: ");
System.out.println(Arrays.toString(rowTotalsRL));
System.out.println("The Total of The Top left to Bottom Right Diagonal is: ");
System.out.println(Arrays.toString(totalsDagLR));
System.out.println("The Total of The Top Right to Bottom Left Diagonal is: ");
System.out.println(Arrays.toString(totalsDagRL));
}
}
}
然后该代码以
takingridnums(..)结束代码>方法,甚至不询问我的输入。我知道我所有的变量都在main中可能会有点奇怪,但我只是想通过将所有需要的变量都放在那里,并以这种方式将它们传递到我的方法中,来解决问题,使事情变得更简单。我还试图避免使用全局变量。我确实在扫描仪上用了一个,因为这要简单得多。如果您能帮助这两个代码中的任何一个正常工作,我们将不胜感激。在您的第二组代码中,将调用您的takingridnums(..)
方法,但您正在创建一个tempsizevel
大的网格。然而,您的tempSizeFill
变量是0,因为它基于main中的userGridSize
而初始化为0。当用户键入所需的网格大小时,tempsizevel
不会自动更新,因此将跳过for
循环
因此,不是:
userGridSize = scanner.nextInt();
tempMultiply = userGridSize * userGridSize;
System.out.println("Your Grid Size Will Be: " + tempMultiply);
takeInGridNums(gridColumns, tempSizeFull, gridRows, gridNums, tempGridColumns, tempGridRows, totalLeftToRight, rowTotalsLR, tempTotal, tempPoint, rowTotalsRL, totalRightToLeft, totalsDagLR, totalDagLeftToRight, totalsDagRL, tempUp, tempDown);`
尝试以下方法:
userGridSize = scanner.nextInt();
tempMultiply = userGridSize * userGridSize;
System.out.println("Your Grid Size Will Be: " + tempMultiply);
gridNums = new int[userGridSize][userGridSize];
int tempSize = gridNums.length;
tempSizeFull = tempSize * tempSize;
takeInGridNums(gridColumns, tempSizeFull, gridRows, gridNums, tempGridColumns, tempGridRows, totalLeftToRight, rowTotalsLR, tempTotal, tempPoint, rowTotalsRL, totalRightToLeft, totalsDagLR, totalDagLeftToRight, totalsDagRL, tempUp, tempDown);
如果进行以下更改:
ArrayList<ArrayList<Integer>> gridNums = new ArrayList<ArrayList<Integer>>();
ArrayList<Integer> rowTotalsLR = new ArrayList<Integer>();
ArrayList<Integer> rowTotalsRL = new ArrayList<Integer>();
ArrayList<Integer> totalsDagLR = new ArrayList<Integer>();
ArrayList<Integer> totalsDagRL = new ArrayList<Integer>();
ArrayList gridNums=new ArrayList();
ArrayList rowTotalsLR=新的ArrayList();
ArrayList rowTotalsRL=新的ArrayList();
ArrayList totalsDagLR=新的ArrayList();
ArrayList totalsDagRL=新的ArrayList();
然后,该循环将如下所示:
int numCols=(int)Math.sqrt(tempMultiply);
对于(int-temp=0;temp!=tempMultiply;temp++){
如果(gridColumns==numCols){gridRows++;gridColumns=0;}
System.out.println(“请输入网格位置的数字:“+gridRows+”,“+gridColumns”);
get(gridRows.add(scanner.nextInt());
gridColumns++;
}
然后,在重写整个代码之后,您将进行类似的更改,以说明从arrays更改为ArrayList的情况。我最终完成了一个成品。基本上,我去掉了所有的按引用传递并创建了实例变量。我是在给我的Java老师发电子邮件询问使用实例变量是否合适后做出这个决定的。她确认并说我应该在这个项目中使用实例变量。这使我决定重新编写整个程序,并在下面创建了它。感谢所有试图帮助我的人,但我以前的代码太乱了,根本没有意义
目前的工作方案:
import java.util.Arrays;
import java.util.Scanner;
public class squareAgain {
static Scanner scan = new Scanner(System.in);
static int[][] userSquare = new int[0][0];
static int[] mathLRTotals = new int[0], mathTBTotals = new int[0], mathDLRTotals = new int[1], mathDRLTotals = new int[1];
static String userMenuInput = "presetByProgrammer";
static int totalElements = 0;
public static void main(String[] args) {
while(userMenuInput != "quit"){
mainMenu();
System.out.print("Your Choice: ");
userMenuInput = scan.next();
switch(userMenuInput.toLowerCase()){
case "rules":
menuOptionRules();
break;
case "play":
menuOptionPlay();
break;
case "quit":
System.out.println("Now Quitting.");
userMenuInput = "quit";
break;
default:
System.out.println("You Typed something wrong.");
break;
}
}
}
private static void mainMenu(){
System.out.println(" Welcome to Magic Square! ");
System.out.println("--------------------------");
System.out.println("Type any of the following:");
System.out.println("--------------------------");
System.out.println("Rules (Displays Rules)");
System.out.println("Play (Starts The Game)");
System.out.println("Quit (Quits The Game)");
System.out.println("--------------------------");
}
private static void menuOptionRules(){
System.out.println("The Rules Are: ");
System.out.println("1: All numbers must be different");
System.out.println(" It will tell you if you have duplicates.");
System.out.println("2: All numbers must add up to be the same Left to right");
System.out.println("3: All numbers must add up to be the same Top to Bottom");
System.out.println("4: All numbers must add up to be the same Diagonal Top left to Bottom Right");
System.out.println("4.A: All numbers must add up to be the same Diagonal Top Right to Bottom Left");
}
private static void menuOptionPlay(){
getUserInputs();
mathLR();
mathTB();
mathDLR();
mathDRL();
outputs();
}
private static void getUserInputs(){
System.out.println("Thank You For Playing.");
System.out.print("Please Enter A Size For Your Square: ");
int userSquareSizeInput = scan.nextInt();
userSquare = new int[userSquare.length+userSquareSizeInput][userSquare.length+userSquareSizeInput];
System.out.println("Array Length is now: " + userSquare.length);
totalElements = userSquareSizeInput * userSquareSizeInput;
System.out.println("This Means You Will Have " + totalElements + " elements." );
System.out.println();
int tempForGridInputRow = 0, tempForGridInputCol = 0;
for(int temp = 0; temp != totalElements; temp++){
if(tempForGridInputCol == userSquare.length){tempForGridInputRow++; tempForGridInputCol = 0;}
System.out.print("Please Eneter A number for Grid Position: " + tempForGridInputRow + " , " + tempForGridInputCol + ": ");
userSquare[tempForGridInputRow][tempForGridInputCol] = scan.nextInt();
tempForGridInputCol++;
}
System.out.println();
}
private static void mathLR(){
mathLRTotals = new int[mathLRTotals.length+userSquare.length];
int tempForGridInputRow = 0, tempForGridInputCol = 0, tempElement = 0, tempTotal = 0;
for(int temp = 0; temp < totalElements; temp++){
tempElement = tempElement + userSquare[tempForGridInputRow][tempForGridInputCol];
tempTotal = tempElement;
tempForGridInputCol++;
if(tempForGridInputCol == userSquare.length){
mathLRTotals[tempForGridInputRow] = tempTotal;
tempForGridInputRow++;
tempForGridInputCol = 0;
tempTotal = 0;
tempElement = 0;
}
}
}
private static void mathTB(){
mathTBTotals = new int[mathTBTotals.length+userSquare.length];
int tempForGridInputRow = 0, tempForGridInputCol = 0, tempElement = 0, tempTotal = 0;
for(int temp = 0; temp < totalElements; temp++){
tempElement = tempElement + userSquare[tempForGridInputRow][tempForGridInputCol];
tempTotal = tempElement;
tempForGridInputRow++;
if(tempForGridInputRow == userSquare.length){
mathTBTotals[tempForGridInputCol] = tempTotal;
tempForGridInputRow = 0;
tempForGridInputCol++;
tempTotal = 0;
tempElement = 0;
}
}
}
private static void mathDLR(){
int tempElement = 0;
for(int temp = 0; temp != userSquare.length; temp ++){
tempElement = tempElement + userSquare[temp][temp];
mathDLRTotals[0] = tempElement;
}
}
private static void mathDRL(){
int tempForGridInputRow = 0, tempForGridInputCol = userSquare.length-1, tempElement = 0;
for(int temp = 0; temp != userSquare.length; temp ++){
tempElement = tempElement + userSquare[tempForGridInputRow][tempForGridInputCol];
mathDRLTotals[0] = tempElement;
tempForGridInputRow++;
tempForGridInputCol--;
}
}
private static void outputs(){
System.out.println("You Entered " + userSquare.length + " As your grid length and height");
System.out.println("This means there was " + totalElements + " elements in your square.");
System.out.println("Here is what you entered: ");
System.out.println(Arrays.deepToString(userSquare));
System.out.println("The totals for each row are: ");
System.out.println(Arrays.toString(mathLRTotals));
System.out.println("The totals for each column are: ");
System.out.println(Arrays.toString(mathTBTotals));
System.out.println("The total of the Left to Right Diagonal: ");
System.out.println(Arrays.toString(mathDLRTotals));
System.out.println("The total of Right to Left Diagonal: ");
System.out.println(Arrays.toString(mathDRLTotals));
System.out.println();
String tempYesForLR = "setByProgrammer";
int tempCompareLR = mathLRTotals[0];
for(int temp = 0; temp != mathLRTotals.length; temp++){
if(tempCompareLR == mathLRTotals[temp]){tempYesForLR = "true";}else{tempYesForLR = "false"; break;}
}
String tempYesForTB = "setByProgrammer";
int tempCompareTB = mathTBTotals[0];
for(int temp = 0; temp != mathTBTotals.length; temp++){
if(tempCompareTB == mathTBTotals[temp]){tempYesForTB = "true";}else{tempYesForTB = "false"; break;}
}
Boolean tempForYesDag = false;
if(mathDLRTotals[0] == mathDRLTotals[0]){tempForYesDag = true;}
if(tempYesForLR == tempYesForTB == tempForYesDag){
System.out.println("All of the rows added up to be: " + mathLRTotals[0]);
System.out.println("You created a Perfect Square!");
System.out.println();
}
else{
System.out.println("Your rows didn't add up to the same number.");
System.out.println("Review what you entered and try again!");
System.out.println();
}
}
导入java.util.array;
导入java.util.Scanner;
公共课又开始了{
静态扫描仪扫描=新扫描仪(System.in);
静态int[]userSquare=newint[0][0];
静态int[]MathlTotals=new int[0],MathtTotals=new int[0],mathDLRTotals=new int[1],MathdrTotals=new int[1];
静态字符串userMenuInput=“presetByProgrammer”;
静态整数totalElements=0;
公共静态void main(字符串[]args){
while(userMenuInput!=“退出”){
主菜单();
System.out.print(“您的选择:”);
userMenuInput=scan.next();
开关(userMenuInput.toLowerCase()){
案例“规则”:
menuOptionRules();
打破
案例“游戏”:
菜单选项播放();
打破
“退出”案例:
System.out.println(“现在退出”);
userMenuInput=“退出”;
打破
违约:
System.out.println(“您键入了错误的内容”);
打破
}
}
}
私有静态void主菜单(){
System.out.println(“欢迎来到魔方!”);
System.out.println(“-----------------------------------”);
System.out.println(“键入以下任一项:”);
System.out.println(“-----------------------------------”);
System.out.println(“规则(显示规则)”;
System.out.println(“Play(启动游戏)”;
System.out.println(“退出(退出游戏)”;
System.out.println(“-----------------------------------”);
}
私有静态void菜单选项规则(){
System.out.println(“规则是:”);
System.out.println(“1:所有数字必须不同”);
System.out.println(“它会告诉您是否有重复项。”);
System.out.println(“2:所有数字的总和必须从左到右相同”);
System.out.println(“3:所有数字的总和必须自上而下相同”);
System.out.println(“4:所有数字的总和必须是从左上到右下的同一对角线”);
System.out.println(“4.A:所有数字的总和必须是从右上到左下的同一对角线”);
}
私有静态void菜单选项播放(){
getUserInputs();
mathLR();
mathTB();
mathDLR();
mathDRL();
输出();
}
私有静态void getUserInputs(){
System.out.println(“感谢您的参与。”);
System.out.print(“请输入正方形的大小:”);
int userSquareSizeInput=scan.nextInt();
userSquare=newint[userSquare.length+userSquareSizeInput][userSquare.length+userSquareSizeInput];
System.out.println(“数组长度现在为:“+userSquare.Length”);
totalElements=userSquareSizeInput*userSquareSizeInput;
System.out.println(“这意味着您将拥有“+totalElements+”elements”);
System.out.println();
int tempForGridInputRow=0,tempForGridInputCol=0;
对于(int-temp=0;temp!=totalElements;temp++){
如果(tempForGridInputCol==userSquare.length){tempForGridInputRow++;tempForGridInputCol=0;}
System.out.print(“请输入网格位置的数字:“+tempForGridInputRow+”,“+tempForGridInputCol+”:”;
userSquare[tempForGridInputRow][tempForGridInputCol]=scan.nextInt();
temputcol++;
}
System.out.println();
}
私有静态void mathLR(){
MathlTotals=newint[MathlTotals.length+userSquare.length];
int tempForGridInputRow=0,tempForGridInputCol=0,tempElement=0,tentitotal=0;
为了(
import java.util.Arrays;
import java.util.Scanner;
public class squareAgain {
static Scanner scan = new Scanner(System.in);
static int[][] userSquare = new int[0][0];
static int[] mathLRTotals = new int[0], mathTBTotals = new int[0], mathDLRTotals = new int[1], mathDRLTotals = new int[1];
static String userMenuInput = "presetByProgrammer";
static int totalElements = 0;
public static void main(String[] args) {
while(userMenuInput != "quit"){
mainMenu();
System.out.print("Your Choice: ");
userMenuInput = scan.next();
switch(userMenuInput.toLowerCase()){
case "rules":
menuOptionRules();
break;
case "play":
menuOptionPlay();
break;
case "quit":
System.out.println("Now Quitting.");
userMenuInput = "quit";
break;
default:
System.out.println("You Typed something wrong.");
break;
}
}
}
private static void mainMenu(){
System.out.println(" Welcome to Magic Square! ");
System.out.println("--------------------------");
System.out.println("Type any of the following:");
System.out.println("--------------------------");
System.out.println("Rules (Displays Rules)");
System.out.println("Play (Starts The Game)");
System.out.println("Quit (Quits The Game)");
System.out.println("--------------------------");
}
private static void menuOptionRules(){
System.out.println("The Rules Are: ");
System.out.println("1: All numbers must be different");
System.out.println(" It will tell you if you have duplicates.");
System.out.println("2: All numbers must add up to be the same Left to right");
System.out.println("3: All numbers must add up to be the same Top to Bottom");
System.out.println("4: All numbers must add up to be the same Diagonal Top left to Bottom Right");
System.out.println("4.A: All numbers must add up to be the same Diagonal Top Right to Bottom Left");
}
private static void menuOptionPlay(){
getUserInputs();
mathLR();
mathTB();
mathDLR();
mathDRL();
outputs();
}
private static void getUserInputs(){
System.out.println("Thank You For Playing.");
System.out.print("Please Enter A Size For Your Square: ");
int userSquareSizeInput = scan.nextInt();
userSquare = new int[userSquare.length+userSquareSizeInput][userSquare.length+userSquareSizeInput];
System.out.println("Array Length is now: " + userSquare.length);
totalElements = userSquareSizeInput * userSquareSizeInput;
System.out.println("This Means You Will Have " + totalElements + " elements." );
System.out.println();
int tempForGridInputRow = 0, tempForGridInputCol = 0;
for(int temp = 0; temp != totalElements; temp++){
if(tempForGridInputCol == userSquare.length){tempForGridInputRow++; tempForGridInputCol = 0;}
System.out.print("Please Eneter A number for Grid Position: " + tempForGridInputRow + " , " + tempForGridInputCol + ": ");
userSquare[tempForGridInputRow][tempForGridInputCol] = scan.nextInt();
tempForGridInputCol++;
}
System.out.println();
}
private static void mathLR(){
mathLRTotals = new int[mathLRTotals.length+userSquare.length];
int tempForGridInputRow = 0, tempForGridInputCol = 0, tempElement = 0, tempTotal = 0;
for(int temp = 0; temp < totalElements; temp++){
tempElement = tempElement + userSquare[tempForGridInputRow][tempForGridInputCol];
tempTotal = tempElement;
tempForGridInputCol++;
if(tempForGridInputCol == userSquare.length){
mathLRTotals[tempForGridInputRow] = tempTotal;
tempForGridInputRow++;
tempForGridInputCol = 0;
tempTotal = 0;
tempElement = 0;
}
}
}
private static void mathTB(){
mathTBTotals = new int[mathTBTotals.length+userSquare.length];
int tempForGridInputRow = 0, tempForGridInputCol = 0, tempElement = 0, tempTotal = 0;
for(int temp = 0; temp < totalElements; temp++){
tempElement = tempElement + userSquare[tempForGridInputRow][tempForGridInputCol];
tempTotal = tempElement;
tempForGridInputRow++;
if(tempForGridInputRow == userSquare.length){
mathTBTotals[tempForGridInputCol] = tempTotal;
tempForGridInputRow = 0;
tempForGridInputCol++;
tempTotal = 0;
tempElement = 0;
}
}
}
private static void mathDLR(){
int tempElement = 0;
for(int temp = 0; temp != userSquare.length; temp ++){
tempElement = tempElement + userSquare[temp][temp];
mathDLRTotals[0] = tempElement;
}
}
private static void mathDRL(){
int tempForGridInputRow = 0, tempForGridInputCol = userSquare.length-1, tempElement = 0;
for(int temp = 0; temp != userSquare.length; temp ++){
tempElement = tempElement + userSquare[tempForGridInputRow][tempForGridInputCol];
mathDRLTotals[0] = tempElement;
tempForGridInputRow++;
tempForGridInputCol--;
}
}
private static void outputs(){
System.out.println("You Entered " + userSquare.length + " As your grid length and height");
System.out.println("This means there was " + totalElements + " elements in your square.");
System.out.println("Here is what you entered: ");
System.out.println(Arrays.deepToString(userSquare));
System.out.println("The totals for each row are: ");
System.out.println(Arrays.toString(mathLRTotals));
System.out.println("The totals for each column are: ");
System.out.println(Arrays.toString(mathTBTotals));
System.out.println("The total of the Left to Right Diagonal: ");
System.out.println(Arrays.toString(mathDLRTotals));
System.out.println("The total of Right to Left Diagonal: ");
System.out.println(Arrays.toString(mathDRLTotals));
System.out.println();
String tempYesForLR = "setByProgrammer";
int tempCompareLR = mathLRTotals[0];
for(int temp = 0; temp != mathLRTotals.length; temp++){
if(tempCompareLR == mathLRTotals[temp]){tempYesForLR = "true";}else{tempYesForLR = "false"; break;}
}
String tempYesForTB = "setByProgrammer";
int tempCompareTB = mathTBTotals[0];
for(int temp = 0; temp != mathTBTotals.length; temp++){
if(tempCompareTB == mathTBTotals[temp]){tempYesForTB = "true";}else{tempYesForTB = "false"; break;}
}
Boolean tempForYesDag = false;
if(mathDLRTotals[0] == mathDRLTotals[0]){tempForYesDag = true;}
if(tempYesForLR == tempYesForTB == tempForYesDag){
System.out.println("All of the rows added up to be: " + mathLRTotals[0]);
System.out.println("You created a Perfect Square!");
System.out.println();
}
else{
System.out.println("Your rows didn't add up to the same number.");
System.out.println("Review what you entered and try again!");
System.out.println();
}
}