import java.util.*; public class linklist { private static class Node { private String data; private Node next; private Node(String item) { data = item; next = null; } } public static Scanner kb = new Scanner(System.in); public static void dumplist(Node l) { Node p; p = l; System.out.println("\nList Contents:"); while (p != null) { System.out.print(p.data + " "); p = p.next; } System.out.println(); } public static void main (String[] args) { Node head=null, n; String w; System.out.print("Enter a word: "); while (kb.hasNext()) { w = kb.next(); n = new Node(w); n.next = head; head = n; dumplist(head); System.out.print("\nEnter a word: "); } } }