We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc= new Scanner(System.in);
List <Integer> first=new <Integer>ArrayList();
int n=sc.nextInt();
for(int i=0;i<n;i++){
int m=sc.nextInt();
first.add(m);
}
int q=sc.nextInt();
for(int i=0;i<q;i++){
String value=sc.nextLine();
if(value.equals("Insert")){
int x=sc.nextInt();
int y=sc.nextInt();
first.add(x,y);
}
else{
int k=sc.nextInt();
first.remove(k);
}
}
for(Integer z:first)
System.out.print(z+" ");
}
}
ques------why I am getting input mismatch exception?
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Solution.main(Solution.java:26)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java List
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.util.;
public class Solution {
} ques------why I am getting input mismatch exception?
Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at Solution.main(Solution.java:26)