这是迄今为止,但无法弄清楚如何显示用户输入的数字 的数量,我知道它与这个数字有关计数方法,但无法弄清楚如何将其实现到此。显示最小,最大,平均值和输入的数字
import java.util.Scanner;
public class Test {
@SuppressWarnings("resource")
public static void main(String[] arg) {
int count = 0;
double sum = 0;
double maximum = 0;
double minimum = 100;
Scanner kb = new Scanner(System.in);
double input = -1;
// Main processing loop...
do {
// Validation loop...
do {
System.out.println("Please enter a number or 0 to quit:");
input = kb.nextDouble();
kb.nextLine();
} while (input > 100);
if (input > 0) {
count++;
sum += input;
if (maximum < input) {
maximum = input;
}
if (minimum > input) {
minimum = input;
}
}
} while (input != 0);
double average = (sum/count);
System.out.println(
"The average is: " + average);
System.out.println(
"Minimum of entered numbers: " + minimum);
System.out.println(
"Maximum of entered numbers: " + maximum);
}
}
只是不'调用println(计数)'... – nhouser9
,谢谢,我得到了工作,但是当我运行它,那只能说明与显示最低的正数,而不是最低沿进入正数否定的。 – Justin