如果两个Scanner.nextLine()
连续出现会怎样?这里,字符串变量'pattern'不存储第二输入。
public static void main (String[] args) {
kmpself test = new kmpself();
Scanner ab = new Scanner(System.in);
String text = ab.nextLine();
String pattern = ab.nextLine();
System.out.println(pattern);
}
答案 0 :(得分:0)
public static void main (String[] args) {
kmpself test = new kmpself();
Scanner ab = new Scanner(System.in);
String text = ab.nextLine();
//changing the line of the input solves the problem
System.out.print("\n");
String pattern = ab.nextLine();
System.out.println(pattern);
}`
答案 1 :(得分:-1)
嗨,我不安静得到你的问题
扫描仪将根据特定的正则表达式重定向要读取的输入流,如果是scanner .nextLine()则是行尾的结尾
阅读更多here
在您的情况下,我2扫描仪实例没有问题