Intersection of two linked lists

import java.util.*;
class LinkedList {

private class Node {

	int data;
	Node next;
}

private Node head;
private Node tail;
private int size;

public int getFirst() throws Exception {
	if (this.size == 0)
		throw new Exception("linked list is empty");

	return head.data;
}

public int getLast() throws Exception {
	if (this.size == 0)
		throw new Exception("linked list is empty");

	return tail.data;
}

public void addLast(int item) {
	// create a new node
	Node nn = new Node();

	nn.data = item;
	nn.next = null;

	// update summary
	if (size == 0) {
		this.head = nn;
		this.tail = nn;
		size++;
	} else

	{
		this.tail.next = nn;
		this.tail = nn;

		size++;
	}

}

public void addFirst(int item) {
	Node nn = new Node();
	nn.data = item;
	nn.next = null;

	if (size == 0) {
		this.head = nn;
		this.tail = nn;
		size++;
	} else {
		nn.next = this.head;
		this.head = nn;
		size++;
	}

}

public int removeFirst() throws Exception {
	Node fn = this.head;

	if (this.size == 0)
		throw new Exception("linked list is empty");

	if (this.size == 1) {
		this.head = null;
		this.tail = null;
		size = 0;
	} else {
		Node np1 = this.head.next;
		this.head = np1;
		size--;
	}

	return fn.data;
}

public static void Intersection(LinkedList list1 ,LinkedList list2) throws Exception {
	  Node heada = list1.head;
	  Node headb = list2.head;
	  
	  if(heada == null || headb == null) {
		  return ;
	  }
	  
	  Node a_pointer = heada;
	  Node b_pointer = headb;
	  
	  while(a_pointer != b_pointer) {
		  if(a_pointer == null) {
			  a_pointer = headb;
		  }else {
			  a_pointer = a_pointer.next;
		  }
		  
		  if(b_pointer == null) {
			  b_pointer = heada;
		  }else {
			  b_pointer = b_pointer.next;
		  }
	  }
	  
	  System.out.println( a_pointer.data);
		
	
	
}

public void display() {

	Node temp = this.head;

	while (temp != null) {
		System.out.print(temp.data + " ");
		temp = temp.next;
	}

}

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

public static void main(String[] args) throws Exception {
	// TODO Auto-generated method stub
	
	    int t = scn.nextInt();
	    

		    LinkedList list1 = new LinkedList();
		    int n1 = scn.nextInt();
		 
		    for (int j = 0; j < n1; j++) {
			    int item = scn.nextInt();
			    list1.addLast(item);
		}
		   

            LinkedList list2 = new LinkedList();
		    int n2 = scn.nextInt();
		 
		    for (int j = 0; j < n2; j++) {
			    int item = scn.nextInt();
			    list2.addLast(item);
		}
		    Intersection(list1,list2);
		   
	
}

}

// sir I’m running in an infinite loop please help with corrrections

sir u just have to check if the node value of LL a == node value of LL b
if so return the value at node

else if nodevalue at LL a > nodeValue atLL b
increment pointer in LL b
else increment pointer in LL a