问题遇到的现象和发生背景
对二维整数数组进行操作
用代码块功能插入代码,请勿粘贴截图
package lab3;
import java.util.Scanner;
public class Part2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the count of columns: ");
int columns = scanner.nextInt();
System.out.println("Enter the count of rows: ");
int rows = scanner.nextInt();
int[][] matrix = new int[rows][columns];
java.util.Random random = new java.util.Random();
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
matrix[i][j] = random.nextInt(10) - 4;
}
int[] countByRows = new int[rows];
//输出二维数组
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
System.out.print(matrix[i][j] + " ");
System.out.println();
}
//计数至少有一个零元素的行
int amount = 0 ;
for (int i = 0; i < rows; i++)
if ( [rows] == 0)
{
amount = amount+ 1 ;
}
System.out.println("The number of rows with at least one zero element is" + amount);
//找出具有相同元素最多的列的列数
}
}
运行结果及报错内容
计数至少有一个零元素的行报错
我想要达到的结果
1.计数至少有一个零元素的行
2.找出具有相同元素最多的列的列数