#### Create And Detect Loop

A
```package com.thealgorithms.datastructures.lists;

import java.util.Scanner;

public final class CreateAndDetectLoop {
private CreateAndDetectLoop() {
}

/**
*
*/

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

/**
* Creates a loop in the linked list.
*
* @see
* GeeksForGeeks: Make a loop at K-th position</a>
* @param	k	position of node where loop is to be created
*/
static void createLoop(Node head, int k) {
return;
}
int count = 1;
while (count < k) { // Traverse the list till the kth node
temp = temp.next;
count++;
}

Node connectedPoint = temp;

while (temp.next != null) { // Traverse remaining nodes
temp = temp.next;
}

temp.next = connectedPoint; // Connect last node to k-th element
}

/**
* Detects the presence of a loop in the linked list.
*
* @see
* 	<a href="https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_and_hare">
* Floyd's Cycle Detection Algorithm</a>
*
*
* @return true if loop exists else false
*/

while (fptr != null && fptr.next != null) {
sptr = sptr.next;
fptr = fptr.next.next;
if (fptr == sptr) {
return true;
}
}

return false;
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

System.out.println("Enter the number of elements to be inserted: ");
int n = sc.nextInt();
System.out.printf("Enter the %d elements: %n", n);
while (n-- > 0) {
}

System.out.print("Given list: ");
System.out.println();

System.out.println("Enter the location to generate loop: ");
int k = sc.nextInt();