Help with Strings!! :(

Joined
Mar 7, 2008
Messages
1
Reaction score
0
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);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help in hangman game 1
Void problem 1
Could someone help me and explain what is wrong here? 4
School Project 1
Java matrix problem 3
Help with Loop 0
Need help!! 1
help me with my code 1

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top