@@ -0,0 +1,1387 @@
+public class LinkedListCycle %7B%0A%0A%09static Node head;%0A%0A%09public static class Node %7B%0A%09%09int data;%0A%09%09Node next;%0A%0A%09%09Node(int data) %7B%0A%09%09%09this.data = data;%0A%09%09%7D%0A%09%7D%0A%0A%09public static boolean hasCycle(Node head) %7B%0A%09%09if (head == null)%0A%09%09%09return false;%0A%09%09Node slow = head;%0A%09%09Node fast = head.next;%0A%09%09while (slow != null && fast != null && fast.next != null) %7B%0A%09%09%09if (slow == fast)%0A%09%09%09%09return true;%0A%09%09%09slow = slow.next;%0A%09%09%09fast = fast.next.next;%0A%09%09%7D%0A%09%09return false;%0A%09%7D%0A%0A%09public static void removeCycle(Node head) %7B%0A%09%09if (head == null)%0A%09%09%09return;%0A%09%09Node slow = head;%0A%09%09Node fast = head.next;%0A%09%09while (slow != null && fast.next != null && fast != null) %7B%0A%09%09%09if (slow == fast)%0A%09%09%09%09break;%0A%09%09%09slow = slow.next;%0A%09%09%09fast = fast.next.next;%0A%09%09%7D%0A%09%09slow = head;%0A%09%09fast = fast.next;%0A%09%09Node prev = fast;%0A%09%09while (slow != null && fast != null) %7B%0A%09%09%09if (slow == fast) %7B%0A%09%09%09%09prev.next = null;%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%09prev = fast;%0A%09%09%09slow = slow.next;%0A%09%09%09fast = fast.next;%0A%09%09%7D%0A%09%7D%0A%0A%09public static void main(String args%5B%5D) %7B%0A%09%09Node n1 = new Node(1);%0A%09%09Node n2 = new Node(2);%0A%09%09Node n3 = new Node(3);%0A%09%09Node n4 = new Node(4);%0A%09%09Node n5 = new Node(5);%0A%09%09Node n6 = new Node(6);%0A%09%09Node n7 = new Node(7);%0A%09%09n1.next = n2;%0A%09%09n2.next = n3;%0A%09%09n3.next = n4;%0A%09%09n4.next = n5;%0A%09%09n5.next = n6;%0A%09%09n6.next = n7;%0A%09%09n7.next = n4;%0A%09%09head = n1;%0A%09%09System.out.println(hasCycle(head));%0A%09%09removeCycle(head);%0A%09%09System.out.println(hasCycle(head));%0A%09%7D%0A%0A%7D%0A

Create LinkedListCycle.java