【发布时间】:2015-12-30 17:32:08
【问题描述】:
这个程序需要输出最小应答数和最大应答数。似乎无法正确处理这一问题。最后,结果还需要包含“输入的最小数量是”和“输入的最大数量是”的结果
{
public static void main(String[] args)
{
// display operational messages
System.out.println("Please enter test scores that range from 0 to 100.");
System.out.println("To end the program enter 999.");
System.out.println(); // print a blank line
// initialize variables and create a Scanner object
double scoreTotal = 0;
int scoreCount = 0;
int testScore = 0;
Scanner sc = new Scanner(System.in);
//declaring what is min and what is max
int x = 100;
int y= 0;
int max = Math.max(x, y); // max is 100
int min = Math.min(x, y); // min is 0
// get a series of test scores from the user
while (testScore != 999)
' enter code here` {
// get the input from the user
System.out.print("Enter score: ");
testScore = sc.nextInt();
// accumulate score count and score total
if (testScore <= 100)
{
scoreCount = scoreCount += 1;
scoreTotal = scoreTotal += testScore;
}
else if (testScore != 999)
System.out.println("Invalid entry, not counted");
}
// display the score count, score total, and average score
double averageScore = scoreTotal / scoreCount;
String message = "\n" +
"Score count: " + scoreCount + "\n"
`enter code here` + "Score total: " + scoreTotal + "\n"
+ "Average score: " + averageScore + "\n";
System.out.println(message);
}
【问题讨论】:
-
您从不尝试确定最小值/最大值?
-
Can't seem to get this one right- 难怪您不尝试它。请尝试并发布您尝试过的内容以及失败的原因。