java编程:有一个3*4的矩阵,要求编程输出其中值最大的那个元素的值,以及它所在的行号和列号。

矩阵如下:
3 5 6 4
4 5 56 68
45 56 98 65
哪位好心的大哥帮帮忙啊,小弟急啊!!!!!!!!!

第1个回答  推荐于2016-09-16
亲测。。。。

public class Max
{
public static void main(String[] args)
{
int[][] array = {{3,5,6,4 },
{4,5,56,68 },
{45,56,98,65}};
int i=0,j=0;
int temp = array[0][0];
for(;i<3;i++)
for(j=0;j<4;j++)
{
if(array[i][i]>temp) temp = array[i][j];
}
System.out.println("Max :"+temp);
}
}本回答被提问者采纳
第2个回答  2008-11-03
int[][] a = {{3,5,6,4,},{4,5,56,68,},{45,56,98,65,},};

int r=0,c=0,max=Integer.MIN_VALUE;
for(int i=0; i<a.length; i++){
for(int j=0; j<a[i].length; j++){
if(max<a[i][j]){
max=a[i][j];
r=i;
c=j;
}
}
}
System.out.println("行:"+(r+1)+" 列:"+(c+1)+" 有最大值:"+max);
相似回答