package ShuZu;
import java.util.Arrays;
import java.util.Scanner;
/**
* 功能说明:求出二维数组中的最大元素值 和 求出它的两个下标,并求出一维数组的平均值。
* @author 夏大昌
* @Date 2022/7/27 18:31
*/
public class ErWeiShuZu {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("输入数组的行数:");
int h = input.nextInt();
System.out.print("输入数组的列数:");
int l = input.nextInt();
int[][] a = new int[h][l];
int j = 0;
int sum=0;//和
int avg=0;//平均值
int th=0;//总长度
for(int i = 0; i < a.length; i++) {
System.out.println("输入第" + (i + 1) + "个数组:");
for (j = 0; j < a[i].length; j++) {
a[i][j] = input.nextInt();
sum = sum + a[i][j];
}
th = th + a[i].length;
}
avg = sum / th;
Location location1=locateLargest(a);
System.out.println("最大元素值: "+location1.maxValue+"\n下表是:"+"("+location1.row+" , "+location1.column+")"+"\n数组平均值:"+avg);
}
public static Location locateLargest(int[][] a) {
Location location = new Location();
int h = 0;
int l = 0;
double maxValue = 0;
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
if(a[i][j]>maxValue){
maxValue=a[i][j];
h =i;
l=j;
}
}
}
location.row = h;
location.column = l;
location.maxValue = maxValue;
return location;
}
}
class Location{
public int row;//下标
public int column;//下标
public double maxValue;//最大值
}