因此,当我运行程序的 main 方法时,它会打印:
Enter number of test cases:
1
Enter string 1
Enter string 2
rat apple cat ear cat apple rat
出于某种原因,它Enter string 1 and Enter string 2
甚至在我为字符串一输入任何内容之前就打印出来了。任何人都可以解释为什么会这样。我的BufferReader
设置方式有问题吗?
代码:
public static void main(String[] args) throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number of test cases: ");
int testcases = in.read();
System.out.println("Enter string 1");
String[] str1 = in.readLine().split(" ");
System.out.println("\nEnter string 2");
String[] str2 = in.readLine().split(" ");
for(int i = 0; i < testcases; i++)
{
String result = lcss(str1, str2);
System.out.println("\nLCSS: "+ result);
System.out.println("\nLCSS Length = "+ result.length());
}
}