import java.util.Scanner;
public class matrixExploration {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the size for the matrix: ");
int size = input.nextInt();
int[][] matrix = matrix(size);
show(matrix);
boolean flagRow = true;
for (int i = 0; i < size; i++) {
if (row(matrix[i], 0)) {
System.out.println("All 0s on row " + (i + 1));
flagRow = false;
}
if (row(matrix[i], 1)) {
System.out.println("All 1s on row " + (i + 1));
flagRow = false;
}
}
if (flagRow)
System.out.println("No same numbers on a row");
boolean flagColumn = true;
for (int i = 0; i < size; i++) {
if (column(matrix, 0, i)) {
System.out.println("All 0s on column " + (i + 1));
flagColumn = false;
}
if (column(matrix, 1, i)) {
System.out.println("All 1s on column " + (i + 1));
flagColumn = false;
}
}
if (flagColumn)
System.out.println("No same numbers on a column");
if (majorDiagonal(matrix))
System.out.println("All " + matrix[0][0] + "s on the major diagonal");
else
System.out.println("No same numbers on the major diagonal");
if (subDiagonal(matrix))
System.out.println("All " + matrix[0][0] + "s on the sub-diagonal");
else
System.out.println("No same numbers on the sub-diagonal");
}
public static int[][] matrix(int size) {
int[][] matrix = new int[size][size];
for (int i = 0; i < size; i++)
for (int j = 0; j < size; j++)
matrix[i][j] = (int) (Math.random() * 10000000) % 2;
return matrix;
}
public static boolean row(int[] ar, int n) {
for (int i:ar)
if (i != n)
return false;
return true;
}
public static void show(int[][] matrix) {
for (int[] m1: matrix) {
for (int m: m1)
System.out.print(m);
System.out.println();
}
}
public static boolean column(int[][] matrix, int n, int i) {
for (int[] ar: matrix) {
if (ar[i] != n)
return false;
}
return true;
}
public static boolean majorDiagonal(int[][] matrix) {
for (int i = 0; i < matrix.length; i++)
if (matrix[i][i] != matrix[0][0])
return false;
return true;
}
public static boolean subDiagonal(int[][] matrix) {
for (int i = 0; i < matrix.length; i++) {
if (matrix[i][matrix.length - 1 - i] != matrix[0][matrix.length - 1])
return false;
}
return true;
}
}