Taking input of the Linked List inputs and size

How to take input of the size of the linked list and ist nodes one by one on the output screen. Please explain a complete programme where we build a linked list by reading its inputs from the keyboard

you need to write a class , say class name is Node.
class Node
{
int data;
Node next;
Node(int data)
{
data=data;
next=null;
}
}

now this class represents nodes of linked list.
your next task is to take inputs and create a node of each input and attach them(link them ) to form a linked list.

what if we don’t know no of inputs? you can take undefined no of inputs in following way:
I am attaching code for taking dynamic number of inputs and forming a linked list:

import java.util.*;
public class Test{
private class Node
{
int data;
Node next;
Node(int data)
{
this.data=data;
this.next=null;
}
public void print(){
System.out.println(“value is:” + data);
}
}
public void display(Node head){
while(head!=null){
head.print();
head = head.next;
}
}
public static void main(String[] args){
Test obj = new Test();
Scanner s = new Scanner(System.in);
String input;
Node head = null, curr=null, newNode=null;
try{
while(!(input = s.next()).equals("")){
newNode = obj.new Node(Integer.parseInt(input));
if(head == null){
head = newNode;
}
else{
curr.next = newNode;
}
curr = newNode;
}
}
catch(Exception ex){
System.out.println(“Done with input”);
}
obj.display(head);
}
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.