I have my code inside a switch case and there is no problem running the program, the user is just never allowed to input anything.
My code:
String post [] = new String [5];
System.out.println("Type your post: ");
String userPost = input.nextLine();
post[0] = userPost;
String hashtags ="";
for (int i = 0; i<post.length && post[i]!=null;i++){
String[]words = post[i].split(" ");
for(int j=0;j<words.length;j++){
if(words[j].trim().startsWith("#")){
hashtags+=words[j].trim() + " ";
}
}
}
if(hashtags.trim().isEmpty())
System.out.println("No hashtags were typed");
else
System.out.println("Hashtags found: " + hashtags );
It immediately proceeds to "No hashtags were typed" after printing type your post. As of now, the program seems to just check an empty string and then promptly outputs "No hashtags were typed". How would one change it so the user is allowed to make an input before the program checks if it consists a hashtag.