I have been trying to create a program in Java that outputs each word found in a string and the number of times they appear. I have been trying to do this without using any arrays or hashmap, and by only using string manipulation methods and string tokenizer, but I can't seem to wrap my head around the logic.
Here is what I have so far.
Scanner sc=new Scanner(System.in);
String input="";
int count=1;
String word="";
System.out.println("Enter your paragraph.");
input=sc.nextLine();
StringTokenizer st=new StringTokenizer(input);
while(st.hasMoreTokens()){
word=st.nextToken();
while(st.hasMoreTokens()){
if(st.nextToken()==word){
count++;
}
}
System.out.println(word+": "+count);
input=input.replaceAll(currentToken," ")
count=1
}
The output I am currently receiving is (the first word entered)=0.
Any help or advice with this or anything to lead me in the right direction?