Ok here's my main and printlinked method:
And here's the ListNode.java:import java.util.Scanner; public class ListTest { public static void main(String []args) { Scanner keyboard = new Scanner(System.in); ListNode head = new ListNode(); ListNode tail = head; head.link = null; System.out.print("Enter integers, seperated with blanks, to put into a linked list (type zero (0) to end): "); int in; in = keyboard.nextInt(); while (in != 0) { ListNode x = new ListNode(); x.link = null; x.data = in; tail = x; } printLinked(head.link); } public static void printLinked(ListNode head) { System.out.println("The numbers in your linked list are:"); while (head != null) { System.out.print(head.data + " "); head = head.link; } } }
PLEASE help mepublic class ListNode { int data; ListNode link; } It builds fine but when I run it this part won't work: public static void printLinked(ListNode head) { System.out.println("The numbers in your linked list are:"); while (head != null) { System.out.print(head.data + " "); head = head.link; } }