package teeeeeee;
public class Hah {
public static void main(String[] args) {
int x = 0;
while (x == 0){
int[][] array = {{0,0,0},{0,0,0},{0,0,0}};
array = fillMatrix();
if (sumRows(array)&& sumColumns(array)&& sumDiagonals(array)){
System.out.println("you have a magic square");
x = 1;
}
else
System.out.println("not a magic square");
}
}
public static int[][] fillMatrix(){
int[][] array = new int [] []
{
{ 2 , 7 , 6 },
{ 9 , 5 , 1 },
{ 4 , 3 , 8 }
};
for (int i = 0; i < array.length; ++i){
System.out.println(array[i]);
}
return array;
}
public static boolean sumRows(int [][] array){
for (int r = 0; r < 3; r++){
int sum = 0;
for (int c = 0; c < 3; c++)
sum += array[r][c];
if (sum != 15)
return false;
}
return true;
}
public static boolean sumColumns(int [][] array){
for (int c = 0; c < 3; c++){
int sum = 0;
for (int r = 0; r < 3; r++)
sum += array[r][c];
if (sum != 15)
return false;
}
return true;
}
public static boolean sumDiagonals(int [][] array){
if (array[0][0] + array[1][1] + array[2][2] != 15)
return false;
if (array[0][2] + array[1][1] + array[2][0] != 15)
return false;
return true;
}
}
how do i print out this array without it being random numbers and letters i have tried many ways but every time it just come out in the randomness and not the array i want it to print any help would be nice. the array i want to rint is in the method fill matrix.