[Java] 纯文本查看 复制代码 public class Test1 {
public static void main(String[] args) {
getArr();
}
static void getArr() {
int[][] arr = new int[4][4];
int max = 0;
int count = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
arr[i][j] = (int)(Math.random() * 10);
System.out.print(arr[i][j] + " ");
if(arr[i][j] > max) {
max = arr[i][j];
}
}
System.out.println();
}
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr.length; j++) {
if(arr[i][j] == max)
count++;
}
}
System.out.println(max + "---" +count);
}
}
只能想到这种笨办法 |