Question
// trying to write code in Java which takes String input from user and puts it in linkedlist as long as user's input is NOT
// trying to write code in Java which takes String input from user and puts it in linkedlist as long as user's input is NOT empty string //Unfortunately my program is not asking for input nor printing the linked list after input is taken // Also confused about usage of .readString(); Explanations appreciated:
public class PopQuiz { static class Node { public boolean isEmpty() { return list.item==null;} private Node list; private String item; public static Node next; {
list= null; while(!StdIn.isEmpty()) { Node old= list; //putting null in old list=new Node(); //making new node and putting it in list list.item= StdIn.readString(); //putting inputs in list.item Node.next= old; //pushing null 1 node to the end } } private static Node t; public static void main(String[] args) { for (Node list= t ; t!= null; t=Node.next) { StdOut.println(t.item); }
} } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started