What is the problem in my code plsl help me

import java.util.Scanner;

public class Main {

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

private class Node {
	int data;
	Node next;

	Node(int data, Node next) {
		this.data = data;
		this.next = next;
	}
}

public Main() {
	this.head = this.tail = null;
	this.size = 0;
}

public int size() {
	return this.size;
}

public void addLast(int data) {
	Node node = new Node(data, null);

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

public void display(Node temp) {

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

private Node getNode(int idx) throws Exception {
	if (idx < 0 || idx >= this.size) {
		throw new Exception("Invalid Index");
	}
	if (this.size == 0) {
		throw new Exception("Linked List is empty");
	}
	Node tempNode = head;
	for (int i = 1; i <= idx; i++) {
		tempNode = tempNode.next;
	}
	return tempNode;
}

public Node kthNodeFromLast(int k) {
	Node slow = this.head;
	Node fast = this.head;
	for (int i = 0; i < k; i++) {
		fast = fast.next;
	}

	while (fast != null) {
		fast = fast.next;
		slow = slow.next;

	}
	return slow;
}

public Node appendToFront(int k) throws Exception {
	int n = this.size;
	 Node prev = getNode(n-k-1); // 1
	 Node curr = getNode(n-k); // 8
	 
	 prev.next = null;
	 
	 Node temp = curr;
	 int count = 0;
	 while(temp.next!=null) {
		 temp = temp.next;
		 count++;
	 }
	 temp.next = head; 
	 return curr;
	 
}

public static void main(String[] args) throws Exception {
	Scanner scanner = new Scanner(System.in);
	Main list = new Main();
	int S = scanner.nextInt();

	for (int i = 0; i < S; i++) {
		list.addLast(scanner.nextInt());
	}
	int k = scanner.nextInt();
	Node head = list.appendToFront(k);

list.display(head);
}

}

hey, do n = n % length for cases where n > length
you can go through this