title: java linked list .This program does not print 8.Why?
body: <p>Singly linked list.</p>
  
  <ol>
  <li>I create node </li>
  <li>add new node</li>
  </ol>
  
  <p>Implementation:</p>
  
  <pre><code>//create node
  class Node {
    int data;
    Node next;
  
    Node(int data) {
      this.data = data;
      next = null;
    }
  }
  public class LinkedList {
  
    //Add new node
    public static void add(Node root, int data){
      Node temp;
      while (root != null) {
        root = root.next;
      }
      temp = new Node(data);
      root = temp;
    }
    //print node
    public static void print(Node root){
      while (root != null) {
        System.out.println(root.data);
        root = root.next;
      }
    }
  
    public static void main(String[] args) {
      Node root ;
      Node iter;
      root = new Node(7);
      iter = root;
      add(iter, 8);
      print(iter);
    }
  
  }
  </code></pre>
  
  <p>I work data structures. I want to linked list but the program is failing.  this program does not print 8.Why?</p>
  
  <p>Where am I making mistakes?</p>