【发布时间】:2010-05-17 09:45:55
【问题描述】:
我刚开始学习,我的一项练习需要帮助。
我需要最终用户输入每个月的降雨量。 然后我需要输出平均降雨量,最高月份和最低月份以及降雨量高于平均水平的月份。
我一直在最高和最低得到相同的数字,我不知道为什么。我正在认真地拔头发。任何帮助将不胜感激。
这是我目前所拥有的:
public class rainfall {
/**
* @param args
*/
public static void main(String[] args)
{
int[] numgroup;
numgroup = new int [13];
ConsoleReader console = new ConsoleReader();
int highest;
int lowest;
int index;
int tempVal;
int minMonth;
int minIndex;
int maxMonth;
int maxIndex;
System.out.println("Welcome to Rainfall");
for(index = 1; index < 13; index = index + 1)
{
System.out.println("Please enter the rainfall for month " + index);
tempVal = console.readInt();
while (tempVal>100 || tempVal<0)
{
System.out.println("The rating must be within 0...100. Try again");
tempVal = console.readInt();
}
numgroup[index] = tempVal;
}
lowest = numgroup[0];
for(minIndex = 0; minIndex < numgroup.length; minIndex = minIndex + 1);
{
if (numgroup[0] < lowest)
{
lowest = numgroup[0];
minMonth = minIndex;
}
}
highest = numgroup[1];
for(maxIndex = 0; maxIndex < numgroup.length; maxIndex = maxIndex + 1);
{
if (numgroup[1] > highest)
{
highest = numgroup[1];
maxMonth = maxIndex;
}
}
System.out.println("The average monthly rainfall was ");
System.out.println("The lowest monthly rainfall was month " + minIndex);
System.out.println("The highest monthly rainfall was month " + maxIndex);
System.out.println("Thank you for using Rainfall");
}
private static ConsoleReader ConsoleReader() {
return null;
}
}
谢谢,
艾米丽
【问题讨论】:
-
Java 中的数组是从零开始的。你最终必须习惯它。