package text1_4;
import java.util.Random;
public class Most_row_column {
public static void main(String[] args) {
java.util.Random random = new java.util.Random();
int[][] data = new int[4][4];
int[] row = new int[4];//得到每行中1的个数
int[] col = new int[4];//得到每列中1的个数
int max_row = 0;
int max_col = 0;
int row_lable = 0;
int col_lable = 0;//记录最多1的行和列的下标
System.out.println("输出产生的0/1矩阵: ");
for(int i = 0;i < 4;i ++)
{
for(int j = 0;j < 4;j ++)
{
boolean value = random.nextBoolean();
if(value)
{
row[i] ++;
data[i][j] = 1;
}
else
data[i][j] = 0;
System.out.print(data[i][j]+" ");
}
System.out.println();
if(max_row < row[i])
{
max_row = row[i];
row_lable = i;
}
}
for(int h = 0;h < 4;h ++)//列
{
for(int g = 0;g < 4;g ++)//行
{
col[h] = col[h] + data[g][h];
}
if(max_col < col[h])
{
max_col = col[h];
col_lable = h;
}
}
System.out.println("输出具有最多1的行(从0行算起): ");
System.out.println("行号: "+row_lable);
for(int i = 0;i < 4;i ++)
System.out.print(data[row_lable][i]+" ");
System.out.println();
System.out.println("输出具有最多1的列(从0列算起): ");
System.out.println("列号: "+col_lable);
for(int i = 0;i < 4;i ++)
System.out.print(data[i][col_lable]+" ");
System.out.println();
}
}



