【发布时间】:2014-04-19 22:01:54
【问题描述】:
所以它的作用是将随机值存储在 31-58 的数组元素中,然后将它们加起来并平均,然后我只是将它们显示出来。
我的问题是:如何将天数数组用于从 31-58(2 月的 28 天)中为每个随机数指定一天并将其存储到第二个数组(工作日 [ ])。这样在程序的最后,我可以根据需要显示日期名称。
我的代码看起来像。(这只是一个片段)
double [] anArray = new double[366];//Keep track of all the days in the year
String [] weekday = new String[366];//I hope to store the day names in this array
String days[]={"monday","tuesday","wednesday","thursday",
"friday","saturday","sunday"};
//---each letter is 0 to start each new month at monday---
int a=0;int b=0;int c=0;int d=0;int e=0;int f=0;int g=0;int h=0;int i=0;
int j=0;int k=0;int l=0;//Days counter
//--These start at 1 to start each new month on the 1st
int jandays=1;int febdays=1;int mardays=1;int aprdays=1;int maydays=1;int jundays=1;
int juldays=1;int augdays=1;int septdays=1;int octdays=1;int novdays=1;int decdays=1;
//Temperatures for February
for(int feb=31;feb <= 58;feb++){
anArray[feb]=(int)(26 + Math.random() * (40-26+1));
//System.out.println(days[b++ %7] + " january "+ (febdays++) +" at "+ anArray[feb]+" degrees"); // This is just testing to see if everything checks out.
febtotal += anArray[feb];
}
febavg= febtotal/31;
System.out.printf("The Average temperature in February: "+"%.2f",febavg);
System.out.println("");
我的要求实际上让我有点困惑 o.o.
【问题讨论】: