Here's my code:
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));
}
}
}
}
After I input
10 3
.b..bz....
The program throws an exception immediately:
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)
I don't even have chance to input pos
and c
.
Could anybody tell me what is wrong in this snippet? Thanks in advance.