這是迄今爲止,但無法弄清楚如何顯示用戶輸入的數字 的數量,我知道它與這個數字有關計數方法,但無法弄清楚如何將其實現到此。顯示最小,最大,平均值和輸入的數字
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