我有一个问题要解决:http ://www.urionlinejudge.com.br/judge/problems/view/1117
使用我的代码,当代码到达最后一行时,方法 readLine 不会返回任何内容。它等待我输入其他输入行。
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class ValidacaoDeNota {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String line = null;
double num;
Double ultimaNotaValida = null;
while ((line=br.readLine()) != null) {
num = Double.parseDouble(line);
if (num < 0 || num > 10) {
bw.write("nota invalida");
} else if (ultimaNotaValida == null) {
ultimaNotaValida = num;
} else {
bw.write("media = " + ((ultimaNotaValida+num) / 2) );
}
bw.write("\n");
}
bw.flush();
}
}