有人是java大佬吗?周一要交的作业一直调试有问题 import java.io.*;
public class ReadAFile
{
public static void main(String[] args) throws FileNotFoundException, IOException
{
double sum =0;
double max =0;
int cnt=0;
String res=new String("");
// 1. opening the file for reading
FileReader f = new FileReader("test.txt");
BufferedReader in = new BufferedReader(f);
// 2. reading lines of text from the file
String line = in.readLine();
while (line != null)
{
String strs[]=line.split(" ");
sum=0;
cnt=0;
for(int i=1;i<strs.length;i++)
{
sum+=Double.parseDouble(strs[i]);
cnt++;
}
if(sum/cnt>max)
res=strs[0];
line = in.readLine();
}
System.out.println (res);
// 3. closing the file
f.close();
}
}
|