我需要找到一个整数出现在矩阵中的次数,无论我做什么,我得到的结果总是"0".最有可能的答案很简单,但我找不到它,我会很感激一些帮助.:)
这是我的代码:
int m, n, c, d, nr = 0, x;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows:");
m = in.nextInt();
System.out.println("Enter the number of columns:");
n = in.nextInt();
int matrix[][] = new int[m][n];
System.out.println("Enter the elements of the matrix:");
for ( c = 0 ; c < m ; c++ )
for ( d = 0 ; d < n ; d++ )
matrix[c][d] = in.nextInt();
System.out.println("Enter the value for number x:");
x = in.nextInt();
for …Run Code Online (Sandbox Code Playgroud)