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();
}

}

Recommended Answers

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

Jump to Post

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);
Jump to Post
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.

Jump to Post

All 10 Replies

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);

gotcha...thanks...

appreciate the help..=)

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.

other than this how we get a full sentence in one line as an input from user

other than this how we get a full sentence in one line as an input from user

if you have questions, please start a new thread

This code works fine, but simply you can use a for loop to print many members details.

commented: If your goal was to improve your user rating by posting fluff garbage in long-dead threads, I would say it backfired. -3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.