I'm trying to solve this problem
https://www.hackerrank.com/challenges/30-dictionaries-and-maps/problem?h_r=next-challenge&h_v=zen
using linked list and ind it's successfully solved in eclipse with all the outputs correct like hackerrank ouputs but when i'm trying to upload my code on the website, it displays a run time error with InputMismatchException
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 Person.main(Person.java:56)
that's my code inside the class
public class Person {
//Node Structure
class Node
{
public String name;
public int phone;
Node next;
};
public Node head;
//Linked List Functions
public void add(String name , int phone ) //Add To End
{
Node n = new Node();
n.name = name;
n.phone = phone;
n.next = head;
head = n;
}
public void search(String name2) //Search inside The List
{
Node n = head;
boolean flag = false;
while(n != null)
{
if(name2.equals(n.name))
{
flag = true;
System.out.println(n.name + "=" + n.phone);
break;
}
n = n.next;
}
if(!flag)
System.out.println("Not found");
}
//Main Function
public static void main(String[] args) {
//Objects From Classes
Scanner s = new Scanner(System.in);
Person p = new Person();
int n = s.nextInt();
for(int i=0 ; i<n ; i++)
{
s.nextLine();
String name = s.nextLine();
int phone = s.nextInt();
p.add(name, phone);
}
s.nextLine();
while(s.hasNext())
{
String name2 = s.next();
p.search(name2);
//System.exit(1);
}
s.close();
}