java - Hashtag Multiple -


i trying find number of unique hashtags in tweet inputted user. example, if inputs "#one #seven #one purple green #red", show 3 unique hashtags "#one, #seven, #red". in code, can 1 tweet, cannot figure out how input multiple tweets , find unique hashtags them.

package edu.bsu.cs121.jmgibson;  import java.util.arraylist; import java.util.arrays; import java.util.hashset; import java.util.scanner; import java.util.set;  public class tweet {   public static void main(string[] args) {     scanner scanner = new scanner(system.in);     system.out.println("please enter tweet");     string tweet = scanner.nextline();     set<string> hashtags = gethashtags(tweet);           system.out.println(hashtags.tostring()); }  public static set<string> gethashtags(string tweet) {     string[] words = tweet.split(" ");     set<string> hashtags = new hashset<string>();     (string word : words) {         if (word.startswith("#")) {             hashtags.add(word);         }     }     return hashtags; } } 

i don't want homework you, i'll offer suggestions:

  1. in main(), you'll need loop asks input , makes calls gethashtags().

  2. instead of creating new hashset inside of gethashtags(), create 1 in main() (outside of loop), , pass in.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -