【发布时间】:2014-03-06 07:05:57
【问题描述】:
在给定的代码中,
输入:
1
7输出:
1
输出应该是 7。我错过了什么??
import java.io.*;
import java.util.*;
class compiler
{
public static void main(String args[] ) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testcases = Integer.parseInt(br.readLine());
// System.out.println("If this statement is added it works as expected!")
int n=Integer.parseInt(br.readLine());
System.out.println(n);
}
}
*我也试过用扫描仪
【问题讨论】:
-
这符合我的预期。
-
@pedromss 我只想打印一个值!!!
-
正常工作,我得到7。
-
这个问题有什么问题?为什么有这么多反对票?
-
它应该打印 7. 处理稀缺资源时可能会出现奇怪的行为。使用 try-finally 块并关闭流是避免意外结果的更安全方法。
标签: java java.util.scanner stdin bufferedreader inputstreamreader