【发布时间】:2020-10-16 13:05:16
【问题描述】:
这是我的示例代码,我无法找到最小的变量。它总是返回零,同时找到最大的变量工作正常。 我使用了相同的技术,但不知道哪里出错了。
请帮帮我。
for (int i = 0; i < n; i++) {
smallest = array[i][0];
largest = array[i][0];//set largest to 0 at each round
mean = 0;
System.out.print("Round " + (i + 1) + " Cards: ");
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
if (in.hasNextInt()) {
for (int j = 0; j < m; j++) {
array[i][j] = in.nextInt();
if (array[i][j] > 9) {
System.out.println("Must be between 1-9");
// Arrays.fill(array, null);
j = 0;
System.out.print("Round " + (i + 1) + " Cards: ");
}
// Largest value
if (array[i][j] >= largest) {
largest = array[i][j];
}
// Smallest value
//smallest = array[i][0];
if (array[i][j] < smallest) {
smallest = array[i][j];
}
// total
mean += array[i][j];
}
break;
} else {
in.next();
}
}
//mean calculation
array[i][m] = largest;
array[i][m + 1] = smallest;
array[i][m + 2] = (int) mean / m;
}
【问题讨论】:
-
是我的方法那么复杂。请帮助我是新手。
-
第二个for循环中使用的变量
m在哪里? -
M 用于打印值
-
m 表示列数和 n 行数
-
m和n有什么价值?
标签: java