用JAVA求3*4矩阵中的最小值和最大值,并输出其行列号

如题所述

public class Abc
{

public static void main(String[] args)
{
int[][] arr = { {1, 2, 3, 4}, {5, 6, -1, 8}, {9, 22, 11, 12}};

int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
int col_min = 0, row_min = 0;
int col_max = 0, row_max = 0;
for (int i = 0; i < arr.length; i++)
{
for (int j = 0; j < arr[i].length; j++)
{
if (arr[i][j] < min)
{
min = arr[i][j];
row_min = i;
col_min = j;
}

if (arr[i][j] > max)
{
max = arr[i][j];
row_max = i;
col_max = j;
}
}
}

System.out.println("最小数:" + min + ",行 = " + row_min + ", 列 =" + col_min);

System.out.println("最大数:" + max + ",行 = " + row_max + ", 列 =" + col_max);
}
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-06-04
二维数组,三行四列,初始化值,循环迭代,找最小值,最大值,行号,列号.追问

能不能帮忙编写一下 急需啊

追答

呐 下面有了,去copy吧.

相似回答