HI..
i had started a thread before about the same code...not sure if i was suppose to keep going in the same one or create a new thread..i am sorry if i did anything wrong mods...

my program should just ask the user to enter words..
"The program must simply ask the user to type in a text since a text is a list of words separated by spaces"

here is my code..please let me know..what i am doing wrong..and what can i do to fix my program..

thanks..

import java.util.Scanner;

public class Words {
public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Type in a text: ");
String text = input.nextString();
}

}

ok..update to my code..

import java.util.Scanner;

public class Words {
public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.print("Type in a text: ");
    String text = input.nextLine();
}

    }

this works fine..but only allows me to enter one word..i want to be able to enter alot of words...how do i do that??

You will need to use either loops, or just create more variables and do the same as you have there.

ok..so this is what i have..

import java.util.Scanner;

public class Words {
public static void main(String[] args) {

    Scanner input = new Scanner(System.in);

    System.out.print("Type in a text: " );
    String text = input.nextLine();

    System.out.print("Type in second text: " );
    String secondtext = input.nextLine();

    System.out.print("Type in third text: " );
    String thirdtext = input.nextLine();

    System.out.print("All the text entered: " + text + secondtext + thirdtext);
}

    }

its good..but then in the end..when it displays all the words together..like a sentence there is no space..the only way it will have space is when after every word that is entered..like for the first first.enter any word and then space..

but i want the spaces in the end without entering space while the word is entered..i hope i explained it clearly..

You will need to print the spaces just as you would print a normal letter.

System.out.print("All the text entered: " + text +" "+ secondtext +" "+ thirdtext);

how to display "you already entered that word" if the word, the user entered, repeated ??

System.out.println("you already entered that word");

it's that easy. now, if you have further questions, please start a new thread and don't revive threads that are no longer active.

This article has been dead for over six months. Start a new discussion instead.