Ok so I have this problem and I've seriously been messing with it for about 3 hours now.
I'm trying to write a program for a homework assignment that continuously gets text input from the user until the user enters “stop” “done” or “end”. Then it prints a String containing all the words the user typed in.
SO:
Here is what i have so far. (I know this is very wrong). I can't figure out a way to get while loop to say basically this: words.equals ! ("stop").
Am I going about this the wrong way?
Thanks for the help!
import java.util.Scanner;
public class InputFilter
{
public static void main( String [] args )
{
//Declare scanner, "kb" in this instance
Scanner kb = new Scanner(System.in);
System.out.println("Enter words and type 'stop', 'done', or 'end' when finished");
String words = kb.next();
String wordies = words;
while(words.equals("stop") || !words.equals("done") || !words.equals("end"))
{
words = kb.next();
wordies = wordies.append(" ") + words;
}
if(words.equals("stop") || words.equals("done") || words.equals("end"))
System.out.println(wordies);
I'm trying to write a program for a homework assignment that continuously gets text input from the user until the user enters “stop” “done” or “end”. Then it prints a String containing all the words the user typed in.
SO:
Here is what i have so far. (I know this is very wrong). I can't figure out a way to get while loop to say basically this: words.equals ! ("stop").
Am I going about this the wrong way?
Thanks for the help!
import java.util.Scanner;
public class InputFilter
{
public static void main( String [] args )
{
//Declare scanner, "kb" in this instance
Scanner kb = new Scanner(System.in);
System.out.println("Enter words and type 'stop', 'done', or 'end' when finished");
String words = kb.next();
String wordies = words;
while(words.equals("stop") || !words.equals("done") || !words.equals("end"))
{
words = kb.next();
wordies = wordies.append(" ") + words;
}
if(words.equals("stop") || words.equals("done") || words.equals("end"))
System.out.println(wordies);