我想了一下,数据量小的情况就直接遍历一下来得最快public class Test {
public static int ARRAY_WIDTH = 5;
public static int ARRAY_HIGHT = 5;
public static void main(String[] args) {
//初始化数组
int[][] arr = new int [ARRAY_WIDTH][ARRAY_HIGHT];
for(int i= 0 ; i < ARRAY_WIDTH; i++){
for(int j=0;j < ARRAY_HIGHT;j++){
arr[i][j] = (int)(Math.random()*100);
}
}
int max = -1;
int tempX = -1;
int tempY = -1;
for(int i=0;i<ARRAY_WIDTH*ARRAY_HIGHT ;i++){
int x = i/ARRAY_WIDTH;
int y = i%ARRAY_WIDTH;
//记录下标
if(max < arr[x][y]){
max = arr[x][y];
tempX = x;
tempY = y;
}
System.out.print(arr[x][y]+"\t");
if(y==ARRAY_WIDTH-1){
System.out.println();
}
}
System.out.println("找出来最大的数是:"+max);
System.out.println("坐标:("+tempX+","+tempY+")");
}
}
|