The code is not working and showing some InputMismatchException

import java.util.*;

class Node {
public int data;
public Node next;

Node(int d) 
{
    data = d;
    next = null;
}

}

class Solution
{
Node intersectionOfTwoLinkedLists(Node l1, Node l2)
{
while(l1!=null)
{
while (l2!=null)
{
if(l1.data==l2.data)
{
return l1;
}
l2=l2.next;
}
l1=l1.next;
}
return null;
}
}

public class Main {

static Scanner sc = new Scanner(System.in);

public static Node buildList(HashMap<Integer, Node> hash) {
    int x = sc.nextInt();
    Node head = new Node(x);
    Node current = head;
    hash.put(x, head);
    while (x != -1) {
        x = sc.nextInt();
        if (x == -1)
            break;
        Node n = new Node(x);
        hash.put(x, n);
        current.next = n;
        current = n;
    }
    current.next = null;
    return head;
}

public static void printLinkedList(Node head) {
    Node temp = head;
    while (temp != null) {
        System.out.print(temp.data + " ");
        temp = temp.next;
    }
    System.out.println();
}

public static void main(String[] args) {

    HashMap<Integer, Node> hash = new HashMap<Integer, Node>();
    Node l1 = buildList(hash);

    Node l2 = null;
    int x = sc.nextInt();
    l2 = new Node(x);
    Node temp = l2;

    while (x != -1) {
        x = sc.nextInt();
        if (x == -1)
            break;
        if (hash.containsKey(x)) {
            temp.next = hash.get(x);
            break;
        }
        Node n = new Node(x);
        temp.next = n;
        temp = n;
    }

    System.out.print("L1 - ");
    printLinkedList(l1);
    System.out.print("L2 - ");
    printLinkedList(l2);

    Solution s = new Solution();

    Node intersectionPoint = s.intersectionOfTwoLinkedLists(l1, l2);
    System.out.println("Intersection at node with data = " + intersectionPoint.data);

}

}

@tishachhabra2702_8fc5a68a2e295e35 your function should look something like this: And don’t compile the code just submit it bcoz test cases are such that it cannot be run on comile code.
Node intersectionOfTwoLinkedLists(Node l1, Node l2) {
/* Code here */
if (l1 == null || l2 == null)
return null;

Node a = l1;
Node b = l2;

while (a != b) {
    a = a == null ? l1 : a.next;
    b = b == null ? l2 : b.next;
}

return a;
}

}

Thanks, I was having problem in compiling only so didn’t check by submitting!
Now it’s fine.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.