Originally Posted by
DJMS
...so far, I learned up from putting integers, doubles, strings, bufferedreader, output to user (the System.out.println), input from user to program yaada, yaada, yaada...
OK. You have learned a lot. We get it.
Originally Posted by
DJMS
The program that we are doing right now involves us looping something if the user does not input anything.
Now, you have to define "anything."
I mean, if the program is executing some kind of
readLine() function from the System.in stream, and I, the user, don't do "anything," it waits for me to do "something." Now, in this case "something" is defined as pressing zero or more character keys in sequence. The sequence is terminated when I, the user, press the 'Enter' key. Until I, the user, press 'Enter' nothing is presented to the program, even though it can't really be said that I am "not doing anything." I mean, I'm pushing keys like crazy. I just haven't hit 'Enter' yet.
Now as for your bit of code:
Assuming
myInput is a
BufferedReader object or some such thing (as I infer from your preamble about all of the things you have learned), the
readLine() method waits for the user to press 'Enter' and then returns the String consisting of a concatenation of the sequence of characters from the keys that the user pressed before hitting the 'Enter' key.
If the user just pressed 'Enter' and nothing else, the
readLine() method returns an "empty" String, and that's what (I'm guessing) you may be looking for, when you say that the user doesn't do "anything."
"Does not input anything" in your problem statement is defined as pressing 'Enter' and nothing else, right?
So: Is you assignment to make a loop that waits for the user to enter some "stuff" and keep looping if the user just presses 'Enter' and nothing else?
Then, starting with what I think I am seeing in your codelet) it could go something like this:
BufferedReader myInput = new BufferedReader(new InputStreamReader(System.in));
.
.
.
String line;
String blank = "";
do {
System.out.print("Enter an integer: ");
line = myInput.readLine();
// Test to see if the line is equal to the String that you have defined as blank.
if (/* The line is not a blank line */) { // Use the String.equals() method to test for equality
/* Do something useful with the non-blank line */
}
} while (/* The line is a blank line */); // If it's a blank line, loop back for more, otherwise terminate the loop
Cheers!
Z