Please remove the errors in the code and correct the logical error if any

import java.util.*;
public class InsertEnd {

//Represent a node of the singly linked list  
class Node{  
    int data;  
    Node next;  

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

//Represent the head and tail of the singly linked list  
public Node head = null;  
public Node tail = null;  

//addAtEnd() will add a new node to the end of the list  
public void addAtEnd(int data) {  
    //Create a new node  
    Node newNode = new Node(data); 

    //Checks if the list is empty  
    if(head == null) {  
        //If list is empty, both head and tail will point to new node  
        head = newNode;  
        tail = newNode;  
    }  
    else {  
        //newNode will be added after tail such that tail's next will point to newNode  
        tail.next = newNode;  
        //newNode will become new tail of the list  
        tail = newNode;  
    }  
}  

//display() will display all the nodes present in the list  
public void display() {  
    //Node current will point to head  
    Node current = head;  
    if(head == null) {  
        System.out.println("List is empty");  
        return;  
    }  
    System.out.println("Adding nodes to the end of the list: ");  
    while(current != null) {  
        //Prints each node by incrementing pointer  
        System.out.print(current.data + " ");  
        current = current.next;  
    }  
    System.out.println();  
}  

public static void main(String[] args) {  

    InsertEnd sList = new InsertEnd(); 
   Scanner sc=new(System.in);
   while(true)
   {
   n=sc.nextInt();
   if(n==-1)
       break;
	   else
    {
    sList.addAtEnd(n);  
    if(sList.detectRemoveLoop())
	
    sList.display(); 

	}
}
} 

public boolean detectRemoveLoop() {

    // detect loop
    Node slow = head;
    Node fast = head;

    while (fast != null && fast.next != null) {

        slow = slow.next;
        fast = fast.next.next;

        if (slow == fast)
            break;
    }

    if (slow == fast) {

        // loop remove
        Node start = head;
        Node loop = slow;

        while (start.next != loop.next) {
            start = start.next;
            loop = loop.next;
        }

        loop.next = null;

        return true;

    } else {

        // loop doesnot exist
        return false;
    }

}

}

https://ide.codingblocks.com/s/345022.

Your code is not correct. You are given a circular linked list and you have to detect the cycle in it and remove the cycle.

Say If INPUT IS 1 2 3 4 5 2 3 -1

Form a linked list 1->2->3->4>5 then you see that 2 has already been visited , so connect the next of 5 to 2 (which has already been created). This way you have created the circular linked list . After that just detect the cycle, remove the cycle, print the new linked list.

Maintain a map or a visited array…whenever you see that a node is already visited, connect next of previous node to that node

On how to remove the circular loop:

We will use Floyd Cycle Detection algorithm to detect and remove the loop. In the Floyd’s algo, the slow and fast pointers meet at a loop node. We can use this loop node to remove cycle. There are following two different ways of removing loop when Floyd’s algorithm is used for Loop detection.

Method 1 (Check one by one):

  1. We know that Floyd’s Cycle detection algorithm terminates when fast and slow pointers meet at a common point. We also know that this common point is one of the loop nodes (2 or 3 or 4 or 5 in the above diagram).
  2. We store the address of this in a pointer variable say ptr2.
  3. Then we start from the head of the Linked List and check for nodes one by one if they are reachable from ptr2.
  4. When we find a node that is reachable, we know that this node is the starting node of the loop in Linked List and we can get pointer to the previous of this node.

Method 2 (Better Solution) :
This method is also dependent on Floyd’s Cycle detection algorithm.

  1. Detect Loop using Floyd’s Cycle detection algo and get the pointer to a loop node.
  2. Count the number of nodes in loop. Let the count be k.
  3. Fix one pointer to the head and another to kth node from head.
  4. Move both pointers at the same pace, they will meet at loop starting node.
  5. Get pointer to the last node of loop and make next of it as NULL.

please send me the correct the correct code

you can refer to this code for better approach

@mohdkaifalam041
You can try out this problem - Cycle Detection and Removal in Linked List

The problem uses the same concept. The only difference is that the linked list is already made for you so you only have to implement the required algorithm and not worry about the taking and parsing input or displaying the output.
You can use either of the methods suggested by @aa1 with slight modifications to solve this problem.

please remove the syntax errors only

thos is the code https://ide.codingblocks.com/s/347317

@mohdkaifalam041
Declare the head node and the inner class as static.