这个java代码哪里不对啊 Exception in thread "main" java.lang.NumberFormatException: null at java.la

importjava.io.BufferedReader;importjava.io.FileNotFoundException;importjava.io.FileRe... import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

//
public class IOLianXi
{

public static void main(String qrgs [] ) {
try{ BufferedReader inputStream = new BufferedReader(new FileReader("data.txt"));
String temp = null;
double sum = 0;
int count = 0;
int max = Integer.MIN_VALUE,min = Integer.MAX_VALUE;
while((temp = inputStream.readLine())!=null);{
int num = Integer.parseInt(temp);
if(num > max) {
max = num;
}
if(num < min) {
min = num;
sum += num;
count++;
}
}
System.out.println("max ="+max);
System.out.println("min ="+min);
System.out.println("Average ="+sum/count);
PrintWriter outputStream = new PrintWriter(new FileWriter("result.txt"));
outputStream.println(max);
outputStream.println(min);
outputStream.println(sum/count);
outputStream.close();
inputStream.close();
}catch(FileNotFoundException e) {
e.printStackTrace();

}catch(IOException e) {
e.printStackTrace();
}
}

}

最后报错
Exception in thread "main" java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at ch01.IOLianXi.main(IOLianXi.java:21)
展开
 我来答
美图赏
2013-04-21 · 知道合伙人数码行家
美图赏
知道合伙人数码行家
采纳数:2638 获赞数:24292
毕业于河南大学电子信息科学与技术专业,学士学位,擅长计算机网络技术。

向TA提问 私信TA
展开全部

while((temp = inputStream.readLine())!=null);{

改为:


while((temp = inputStream.readLine())!=null){

多了一个“;”号啊


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
//
public class IOLianXi {
public static void main(String qrgs[]) {
try {
BufferedReader inputStream = new BufferedReader(new FileReader(
"data.txt"));
String temp = null;
double sum = 0;
int count = 0;
int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
while ((temp = inputStream.readLine()) != null)
{
int num = Integer.parseInt(temp);
if (num > max) {
max = num;
}
if (num < min) {
min = num;
sum += num;
count++;
}
}
System.out.println("max =" + max);
System.out.println("min =" + min);
System.out.println("Average =" + sum / count);
PrintWriter outputStream = new PrintWriter(new FileWriter(
"result.txt"));
outputStream.println(max);
outputStream.println(min);
outputStream.println(sum / count);
outputStream.close();
inputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式