I tried many times but having problem in some test cases

import java.util.*;
public class Main
{
public static class LinkedList
{
private class Node
{
int data;
Node next;
}
private Node head;
private Node tail;
private int size;

	public void display()
	{
		Node temp=head;					
		while(temp!=null)
		{
			System.out.print(temp.data+" ");
			temp=temp.next;
		}
	}
	public void addLast(int item)
	{
		Node nn=new Node();
		nn.data=item;
		
		if(size>0)
			tail.next=nn;
		if(size==0)
			head=tail=nn;
		else
			tail=tail.next;
		size++;
	}
	public void append (int k)
	{
	    if(k>=size )
	    return;
	    Node prev,cur;
	    prev=head;
	    cur=prev.next;
	    for(int i=1;i<(size-k);i++)
	   {
	       prev=cur;
	       cur=cur.next;
	   }
	       prev.next=null;
	       tail.next=head;
	       head=cur;
	}
}
public static void main(String[] args) 
{
	Scanner sc=new Scanner (System.in);
	LinkedList list=new LinkedList();
	int n=sc.nextInt();
	for(int i=0;i<n;i++)
	{
	    list.addLast(sc.nextInt());
	}	
	int k=sc.nextInt();
	list.append(k);
	list.display();
}

}

@tishachhabra2702_8fc5a68a2e295e35 You are failing test cases like :
4
1 2 3 4
5
Correct output : 4 1 2 3
Your output : 1 2 3 4
Debug your code for this input.
To avoid this problem when K is greater than the size of list you dont just need to return you have to update the value of k = k%size(); For example if size of list is 4 and k given is 5. Then appending the list 5 times is equivalent to appending it 1 times bcoz after 4 times the list will be in its original position.
So just use k as k = k%size;
Corrected Code : (Look for comments in append function) :

import java.util.*;
public class Main
{
public static class LinkedList
{
private class Node
{
int data;
Node next;
}
private Node head; 
private Node tail;
private int size;

	public void display()
	{
		Node temp=head;					
		while(temp!=null)
		{
			System.out.print(temp.data+" ");
			temp=temp.next;
		}
	}
	public void addLast(int item)
	{
		Node nn=new Node();
		nn.data=item;
		
		if(size>0)
			tail.next=nn;
		if(size==0)
			head=tail=nn;
		else
			tail=tail.next;
		size++;
	}
	public void append (int k)
	{ // if statement is removed here
	    k = k%size;
		if(k == 0)
		return;//No changes required.
	    Node prev,cur;
	    prev=head;
	    cur=prev.next;
	    for(int i=1;i<(size-k);i++)
	   {
	       prev=cur;
	       cur=cur.next;
	   }
	       prev.next=null;
	       tail.next=head;
	       head=cur;
	}
}
public static void main(String[] args) 
{
	Scanner sc=new Scanner (System.in);
	LinkedList list=new LinkedList();
	int n=sc.nextInt();
	for(int i=0;i<n;i++)
	{
	    list.addLast(sc.nextInt());
	}	
	int k=sc.nextInt();
	list.append(k);
	list.display();
}
}

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.