import java.util.*;

class Node {
        int data;
        Node next;
        
        Node(int x){
            data = x;
            next = null;
        }
}
    
public class MyClass {
  
    public static void main(String args[]) {
        
     Scanner sc = new Scanner(System.in);
     
     Node head = null;
     Node pre = head;
     int x = sc.nextInt();
     
     while(x != -1){
         
         if(head == null){
             head = new Node(x);
             pre = head;
         }
         else{
             pre.next = new Node(x);
             pre = pre.next;
         }
         
         x = sc.nextInt();
     }
     
     
     while(head != null){
         System.out.print(head.data + " -> ");
         head = head.next;
     }
     
      System.out.print("Null");
    
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: