M
mmoski
I've refined my code to make it nice and basic.
import java.util.Scanner;
public class Parse {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
Node head = null;
Node prev = null;
String read = sc.next();
Node a = new Node();
while(sc.hasNext()){ // <-- PROBLEM AREA.
a.data = read;
if(head == null){
head = a;
}else{
prev.next = a;
}
prev = a;
read = sc.next();
}
for(Node pointer = head; pointer != null; pointer = pointer.next)
{
System.out.println(pointer.data);
}
}
}
class Node{
public Node next;
public String data;
}
First off, the list has to be of my own design, so the linkedList
class is useless here. My problem is the while loop. I know that the
scanner usually blocks for whatever reason. My question is, does
anybody have a suggestion for me? If the scanner stalls waiting for
more input, how do I make it un-stall?
import java.util.Scanner;
public class Parse {
public static void main (String[] args) {
Scanner sc = new Scanner(System.in);
Node head = null;
Node prev = null;
String read = sc.next();
Node a = new Node();
while(sc.hasNext()){ // <-- PROBLEM AREA.
a.data = read;
if(head == null){
head = a;
}else{
prev.next = a;
}
prev = a;
read = sc.next();
}
for(Node pointer = head; pointer != null; pointer = pointer.next)
{
System.out.println(pointer.data);
}
}
}
class Node{
public Node next;
public String data;
}
First off, the list has to be of my own design, so the linkedList
class is useless here. My problem is the while loop. I know that the
scanner usually blocks for whatever reason. My question is, does
anybody have a suggestion for me? If the scanner stalls waiting for
more input, how do I make it un-stall?