我不知道我表达清楚了没有,但是我已经成功打印出最小值和最大值了,但我似乎无法找出它们所在的确切行和列。
以下是我的代码:
double max = m[0][0];
double min = m[0][0];
System.out.println("The matrix is : ");
for(int i = 0; i < m.length; i++)
{
for ( int j = 0; j < m[i].length; j++ )
{
System.out.printf(" " + "%6.1f " , m[i][j]);
if (m[i][j] > max)
max = m [i][j];
else if
(m[i][j] < min)
min = m [i][j];
我该如何表述他们的位置?例如:(“最大数在第1行,第2列”)之类的内容......像这样的东西。 我真的很感激任何帮助。
max = m[i][j]
时,同时也要存储位置信息。因此,在顶部添加double max = m[0][0]; int x = 0; int y = 0;
,其中x
和y
是坐标。在max = m[i][j]
下面,你需要写上x = i; y = j;
。 - RaminS