在我的代码中,我从控制台获取输入并像这样读取它:
InputStreamReader sc = new InputStreamReader(System.in);
BufferedReader bufRead = new BufferedReader(sc);
但是当我无法读取最后一行输入时?
例如:如果我想读取 c 并且控制台输入如下所示,
当 c 之后什么都没有时,它没有得到
a
b
c(EOF)
但是对于像这样的输入控制台,在 c 之后有一行可以读取 c
a
b
c
(EOF)
实际代码:
InputStreamReader sc = new InputStreamReader(System.in);
BufferedReader bufRead = new BufferedReader(sc);
String s = bufRead.readLine();
int t = Integer.parseInt(s);
int k = 0; // no. of city
for (int l = 0; l < t; l++) {
s = bufRead.readLine();
k = Integer.parseInt(s);
cityDetails = new String[3][k];
for (int j = 0; j < k; j++) {
s = bufRead.readLine();
StringTokenizer st = new StringTokenizer(s);
cityDetails[0][j] = st.nextToken();
cityDetails[1][j] = st.nextToken();
cityDetails[2][j] = st.nextToken();
}
s = bufRead.readLine();
dist = Double.parseDouble(s);
System.out.println(dist);
}