我需要从文件中读取星期几和温度。我的程序需要写出一周中的文件,高温,低温和每日平均值。我需要使用数组。这是我的代码:
import java.io.File;
import java.util.Formatter;
import java.util.Scanner;
public class dowwithfiles
{
public static void main(String[] args)
{
try
{
Scanner scanner = new Scanner(new File("Dowinputnumbers.txt"));
Formatter formatter = new Formatter(new File("Dowoutputnumbers.txt"));
while(scanner.hasNext())
{
int dow = scanner.nextInt();
int temp = scanner.nextInt();
int [] dows;
dows = new int[8];
int [] hightemps;
hightemps = new int[8];
int [] lowtemps;
lowtemps = new int[8];
formatter.format("%d %d\n",dow, temp, dows, hightemps, lowtemps);
{
if(dow == 1);
dow = dows[1];
temp = hightemps[1];
temp = lowtemps[1];
if(lowtemps[1] > hightemps[1])
lowtemps[1] = hightemps[1];
else
hightemps[1] = lowtemps[1];
if(dow == 2);
dow = dows[2];
temp = hightemps[2];
temp = lowtemps[2];
if(lowtemps[2] > hightemps[2])
lowtemps[2] = hightemps[2];
else
hightemps[2] = lowtemps[2];
if(dow == 3);
dow = dows[3];
temp = hightemps[3];
temp = lowtemps[3];
if(lowtemps[3] > hightemps[3])
lowtemps[3] = hightemps[3];
else
hightemps[3] = lowtemps[3];
if(dow == 4);
dow = dows[4];
temp = hightemps[4];
temp = lowtemps[4];
if(lowtemps[4] > hightemps[4])
lowtemps[4] = hightemps[4];
else
hightemps[4] = lowtemps[4];
if(dow == 5);
dow = dows[5];
temp = hightemps[5];
temp = lowtemps[5];
if(lowtemps[5] > hightemps[5])
lowtemps[5] = hightemps[5];
else
hightemps[5] = lowtemps[5];
if(dow == 6);
dow = dows[6];
temp = hightemps[6];
temp = lowtemps[6];
if(lowtemps[6] > hightemps[6])
lowtemps[6] = hightemps[6];
else
hightemps[6] = lowtemps[6];
if(dow == 7);
dow = dows[7];
temp = hightemps[7];
temp = lowtemps[7];
if(lowtemps[7] > hightemps[7])
lowtemps[7] = hightemps[7];
else
hightemps[7] = lowtemps[7];
break;
}
}
// flush the buffer to disk (makes sure everything gets
// written out to the file)
formatter.flush();
formatter.close();
}
catch(Exception e)
{
double[] highTemps;
highTemps = new double[7];
Scanner scanner = new Scanner(System.in);
int dow = scanner.nextInt();
highTemps[dow - 1] = scanner.nextDouble();
{
}
}
}
}