Hello everyone hows it going
I've only recently been introduced to arrays and require a bit of help with a small exercise I was doing earlier. Here is the question :
Write a program which reads a sequence of words, and prints a count of the number of distinct words. An example of input/output is
should I stay or should I go
5 distinct words
I have solved the question below, without using an array but I presume an array is what the question requires as the exercises are related to the sections being studied. Could anybody show me how I would use one in my solution instead?
public class Ex1 { public static void main(String[] args) { System.out.println("Enter Sentence:"); int count=0; while(!Console.endOfFile()) { String word = Console.readToken(); if(word.length()> 1) { count++; } } System.out.println("Number of distinct words is " + count); } // end of main } // end of class