Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //diagonal sum
- //_____________________________________________________
- //calculates the diagonal sums of a 3x3 square
- public static void ThreeByThreeDSum(int magicSquare[][]){
- int dSumTL_BR = magicSquare[0][0] +magicSquare[1][1]+magicSquare[2][2];
- int dSumTR_BL = magicSquare[0][2] +magicSquare[1][1]+magicSquare[2][0];
- //System.out.println("dSumTL_BR IS: "+dSumTL_BR);
- //System.out.println("dSumTR_BL IS: "+dSumTR_BL);
- if(dSumTL_BR == dSumTR_BL){
- threeBythreeDiagTotal = true;
- }else{
- threeBythreeDiagTotal = false;
- }
- }//ThreeByThreeDSum
- //calculates the diagonal sums of a 4x4 square
- public static void FourByFourDSum(int magicSquare[][]){
- int dSumTL_BR = magicSquare[0][0] +magicSquare[1][1]+magicSquare[2][2]+magicSquare[3][3];
- int dSumTR_BL = magicSquare[0][3] +magicSquare[1][2]+magicSquare[2][1]+magicSquare[3][0];
- //System.out.println("dSumTL_BR IS: "+dSumTL_BR);
- //System.out.println("dSumTR_BL IS: "+dSumTR_BL);
- if(dSumTL_BR == dSumTR_BL){
- fourByFourDiagTotal = true;
- }else{
- fourByFourDiagTotal = false;
- }
- //System.out.println("value of fourByFourDiagTotal is: "+fourByFourDiagTotal);
- }//ThreeByThreeDSum
- //print array
- //_______________________________________________________________________________________________
- public static void printArray(int magicSquare[][]){
- for (int row = 0; row < magicSquare.length; row++) {
- for (int col = 0; col < magicSquare.length; col++) {
- System.out.print(magicSquare[row][col] + "\t");
- }// col
- System.out.println();
- }// row
- }//printArray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement