In article <1190004962.654798.105...@57g2000hsv.googlegroups.com>,
mmoski <mmo...@gmail.com> wrote:
On Sep 16, 11:35 pm, Patricia Shanahan <p...@acm.org> wrote:
mmoski wrote:
[ snip ]
Perhaps if I were to use a read line to wrap the whole while and it
could reach it's EOF when it detects a blank line ie: by hitting enter
twice while in the console. This is my next step but I fear that I'll
still stall because I don't get how the program will make it to the
next line because it has to break the nested while loop first.
Basically I want the user to type in input such as:
input one this is something
input B this is something else
hello world
I want it to read in a line and then using another while loop inside
the first I want it to then read each token in the line into a list.
In the end it should put the head node of each list into an array to
make an array of lists, which will then be processed in a certain
way. I had this EXACT problem last year and never got a solution. I
know that sc.next() will never return null, and that it blocks while
waiting for input.
I know what doesn't work.
What does?
If you want to read input a line at a time, how about using a
BufferedReader? Here's a quickly-hacked-together example of using
one to read input a line at a time, until a blank line is detected.
It compiles and runs for me, but no claims about all details being
best-practice.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class EchoUntilBlank {
public static void main (String[] args) throws IOException {
// probably should deal with the IOException in the code
// rather than just throwing it, but -- quick hack for now
BufferedReader br =
new BufferedReader( new InputStreamReader(System.in));
String line = null;
while(((line = br.readLine()) != null) && (!line.equals(""))) {
System.out.println(line); // replace with your processing
}
}
}
--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
matter). If the lines are all text and you really want to process