Advertisement
Guest User

leech code

a guest
Feb 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.54 KB | None | 0 0
  1. //diagonal sum
  2. //_____________________________________________________
  3.  
  4. //calculates the diagonal sums of a 3x3 square
  5. public static void ThreeByThreeDSum(int magicSquare[][]){
  6.     int dSumTL_BR = magicSquare[0][0] +magicSquare[1][1]+magicSquare[2][2];
  7.     int dSumTR_BL = magicSquare[0][2] +magicSquare[1][1]+magicSquare[2][0];
  8.     //System.out.println("dSumTL_BR IS: "+dSumTL_BR);
  9.     //System.out.println("dSumTR_BL IS: "+dSumTR_BL);
  10.    
  11.     if(dSumTL_BR == dSumTR_BL){
  12.         threeBythreeDiagTotal = true;
  13.     }else{
  14.         threeBythreeDiagTotal = false;
  15.     }
  16. }//ThreeByThreeDSum
  17.  
  18. //calculates the diagonal sums of a 4x4 square
  19. public static void FourByFourDSum(int magicSquare[][]){
  20.     int dSumTL_BR = magicSquare[0][0] +magicSquare[1][1]+magicSquare[2][2]+magicSquare[3][3];
  21.     int dSumTR_BL = magicSquare[0][3] +magicSquare[1][2]+magicSquare[2][1]+magicSquare[3][0];
  22.     //System.out.println("dSumTL_BR IS: "+dSumTL_BR);
  23.     //System.out.println("dSumTR_BL IS: "+dSumTR_BL);
  24.    
  25.     if(dSumTL_BR == dSumTR_BL){
  26.         fourByFourDiagTotal = true;
  27.     }else{
  28.         fourByFourDiagTotal = false;
  29.     }
  30.     //System.out.println("value of fourByFourDiagTotal is: "+fourByFourDiagTotal);
  31. }//ThreeByThreeDSum
  32.  
  33.  
  34.  
  35. //print array
  36. //_______________________________________________________________________________________________
  37.  
  38. public static void printArray(int magicSquare[][]){
  39.     for (int row = 0; row < magicSquare.length; row++) {
  40.         for (int col = 0; col < magicSquare.length; col++) {
  41.             System.out.print(magicSquare[row][col] + "\t");
  42.         }//  col
  43.         System.out.println();
  44.     }// row
  45. }//printArray
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement