1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
erastova [34]
3 years ago
6

g Write a program that allows a user to input any text in your program. Using the tools that we have discussed, your program sho

uld output how many unique words were in the input and then output how many words were unique.
Computers and Technology
1 answer:
Paladinen [302]3 years ago
5 0

Answer:

Explanation:

The following function/program is written in Java. It asks the user for a sentence as an input and then splits that sentence into an array of words. Then it creates an arrayList for all of the unique words, comparing each word in the sentence with all of those in the ArrayList. If a word is found in the ArrayList it cancels the loop and moves on the next word in the sentence. Finally, it counts all of the unique words in the ArrayList and prints that total to the screen.

public static void uniqueWords() {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter a sentence:");

       String sentence = in.nextLine();

       String words[] = sentence.split(" ");

       ArrayList<String> uniqueWords = new ArrayList<>();

       for (int x = 0; x < words.length; x++) {

           boolean exists = false;

           for (int i = 0; i < uniqueWords.size(); i++) {

               if (words[x].equals(uniqueWords.get(i))) {

                   exists = true;

                   break;

               }

           }

           if (exists == false) {

               uniqueWords.add(words[x]);

           }

       }

       System.out.println(uniqueWords.size());

   }

You might be interested in
What might the purpose be for a sata-style power connector on a motherboard?
kozerog [31]
To power a storage device (HDD, SSD)
4 0
3 years ago
Can someone write me a design brief about a stadium​
Delicious77 [7]

Btw..which dtadium do u want cricket or football!?

3 0
3 years ago
Read 2 more answers
Please help me please i’ll give brainli
DaniilM [7]
Answer: a digital bulletin board
4 0
3 years ago
When you are checking an electric heating appliance, the first test made should be for
PSYCHO15rus [73]
The answer would be to first check the normal voltage supply so that there is enough electric current flowing for the electric heating appliance to work or run.
7 0
4 years ago
Why does to much carbon in the atmosphere cause a problem
sweet [91]
Carbon retains heat in the atmosphere. It is a greenhouse gas and is linked to global warming.
7 0
4 years ago
Read 2 more answers
Other questions:
  • Why do bullies and criminals often say things online they otherwise wouldn’t say
    9·2 answers
  • Define a function below, get_subset, which takes two arguments: a dictionary of strings (keys) to integers (values) and a list o
    8·1 answer
  • 3. The invention of the transistor was important to the development of computers because it
    5·1 answer
  • Your task is to improve a multi-threaded program that frequently writes small entries to a shared file by introducing a layer th
    7·1 answer
  • Give three reasons why you think ETL functions are mostchallenging in data warehouse environment.
    13·1 answer
  • Consider the following code segment. The code is intended to read nonnegative numbers and compute their product until a negative
    11·1 answer
  • Consider the following class interfaces:
    8·1 answer
  • What is the output?
    12·1 answer
  • (python) Given the formula for conversion from Celsius to Fahrenheit
    10·1 answer
  • Which data type is used to teach a Machine Learning (ML) algorithm during structured learning?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!