gpt4 book ai didi

java - 为什么会在这段代码中抛出 java.util.InputMismatchException?

转载 作者:行者123 更新时间:2023-11-30 08:03:28 25 4
gpt4 key购买 nike

<分区>

这是我的代码:

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int n = in.nextInt();
int m = in.nextInt();
String s = in.nextLine();
for (int i = 0; i < m; i++) {
int pos = in.nextInt(); // <- Line 14
char c = (char)in.nextByte();
s = s.substring(0, pos) + c + (pos + 1 < n ? s.substring(pos + 1) : "");
System.out.println(f(s));
}
}
}
}

输入后

10 3
.b..bz....

程序立即抛出异常:

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at Test.main(Test.java:14)

我什至没有机会输入 posc

有人能告诉我这段代码有什么问题吗?提前致谢。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com