所以我想打印这个代码..它说:印刷阵列
非 - 静态方法雨水不能从静态上下文访问。
现在的问题是打印所有月份的名称及其降雨量并列和总平均值以及降雨量最高和最低的月份。
请帮我一把。
public class rainfall
{
String[] rain = { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
double[] values = { 0.40,0.94,3.21,3.74,1.73,1.03,1.27,2.58,6.98,6.90,2.80,2.53};
public double Total(double total)
{
total = 0;
for(int i = 0 ; i < values.length ; i ++)
{
total += values[i];
}
return total;
}
public double Average(double average)
{
double total = 0;
Total (total);
for (int j = 0; j < values.length; j ++)
{
average = total/values.length ;
}
return average;
}
public String mostRain (double high,String highest)
{
high = values[0];
for(int i = 1 ; i < rain.length ; i ++)
{
if (values[i]>high)
{
highest = rain[i];
}
return highest;
}
}
public String leastRain (String least, double low)
{
least = "";
low= values[0];
for(int i = 1; i < rain.length ; i++)
{
if (values[i]<low)
{
least = rain[i];
}
return least;
}
}
public static void main(String[]Args)
{
String highest = "" ;
String least = "";
double total = 0 ;
double average = 0 ;
double high = 0;
double low = 0;
System.out.println(" AUSTIN Tx RAINFALL 2009 ");
for(int i = 0 ; i < rain.length ; i ++)
{
System.out.println(rain[i]+"\t"+values[i]);
}
System.out.println(Total(total));
System.out.println(Average(average));
System.out.println(mostRain(highest,high));
System.out.println(leastRain(least,low));
}
}
您可能要检查出[类的方法和字段]官方教程(http://docs.oracle.com/javase/tutorial/java/ javaOO/classvars.html)。 –