Help with Strings!! :(

Discussion in 'Java' started by jojobaba, Mar 7, 2008.

  1. jojobaba

    jojobaba

    Joined:
    Mar 7, 2008
    Messages:
    1
    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);
     
    jojobaba, Mar 7, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kurt Krueckeberg
    Replies:
    2
    Views:
    717
    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
    Nov 17, 2004
  2. Rick

    Comparing strings from within strings

    Rick, Oct 21, 2003, in forum: C Programming
    Replies:
    3
    Views:
    388
    Irrwahn Grausewitz
    Oct 21, 2003
  3. Klaus Neuner
    Replies:
    7
    Views:
    498
    Klaus Neuner
    Jul 26, 2004
  4. Girish Sahani
    Replies:
    17
    Views:
    574
    Boris Borcic
    Jun 9, 2006
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    768
    Malcolm
    Jun 24, 2006
Loading...

Share This Page