【发布时间】:2019-02-19 10:29:28
【问题描述】:
我想从控制台扫描下面的输入,但BufferedReader 在输入 3 行后没有扫描。请帮忙 ....
以下是我的代码
public static void main(String args[]) throws IOException
{
root = new trienode();
System.out.println("enter inputs");
BufferedReader s = new BufferedReader (new InputStreamReader(System.in));
String[] s1 = s.readLine().split(" ");
int n = Integer.parseInt(s1[0]);
int l = Integer.parseInt(s1[1]);
for(int i=0;i<n;i++)
{
String[] s2 = s.readLine().split(" ");
String key=s2[0];
int w=Integer.parseInt(s2[1]);
//Insert(key , w);
}
for(int j=0;j<l;j++)
{
String s3 = s.readLine();
if(search(s3)!=-1)
System.out.println(search(s3));
}
}
我的输入是
2 1
abc 10
gef 9
ghi
无法扫描ghi......
请帮忙
【问题讨论】:
-
函数
search有什么作用?需要MCVE -
将 for 循环更改为
i<=n,但您仍然会得到ArrayOutOfBoundException,因为当您阅读ghi时,s2[1]将没有价值 -
你确定第3行和第4行是用
\n字符隔开的 -
调试,打印 n,l,key,w 并检查它们是否正确
-
是的,我被骗了,n、l、key、w 的值是正确的......
标签: java input java.util.scanner bufferedreader