Write a program that generate 6*6 two-dimensional matrix, filled with 0’s and 1’s,display the matrix

preview_player
Показать описание
Write a program that generate 6*6 two-dimensional matrix, filled with 0’s and 1’s, display the matrix, check every raw and column have an odd number’s of 1’s.
Рекомендации по теме
Комментарии
Автор

import java.util.Scanner;
class p11
{
public static int[][] fill_matrix()
{
int i, j;
int [][]mat = new int[6][6];
for(i=0; i<6; i++)
{
for(j=0; j<6; j++)
{
mat[i][j] = (int)((Math.random()*5)%2);
}
}
return mat;
}
public static void displayMatrix(int [][]mat)
{
int i, j;
Values are :\n");
for(i=0; i<6; i++)
{
for(j=0; j<6; j++)
{
" ");
}
System.out.println();
}
}
public static void main(String commandLineArguments[])
{
int mat1[][];
int i, j, n, a;
mat1 = fill_matrix();
displayMatrix(mat1);
System.out.println("Rows having odd number of 1's are : ");
for(i=0; i<6; i++)
{
a=0;
for(j=0; j<6; j++)
{
if(mat1[i][j] == 1)

}
if(a % 2 != 0)
{
System.out.println("Row - " + (i+1) + " have odd number of 1's");
}
}
System.out.println("Columns having odd number of 1's are : ");
for(i=0; i<6; i++)
{
a=0;
for(j=0; j<6; j++)
{
if(mat1[i][j] == 1)

}
if(a % 2 != 0)
{
- " + (i+1) + " have odd number of 1's");
}
}
}
}

Kcodeofficial