java - How do I check if a string contains keywords? -


i'm writing program asks user enter keywords, , essay, , checks how many keywords used in essay.

current output:


enter keywords:

dog, cat

enter essay:

i cat

exception in thread "main" java.lang.runtimeexception


desired output:


enter keywords:

dog, cat

enter essay:

i cat

1


here's code far:

static int keywordschecker(string shortessay, string keywords) {         int count = 0;          (int = 0; < keywords.length(); i++) {              string[] ary = keywords.split(",");              if (shortessay.contains(ary)) {                 count++;             }             system.out.println(count);           }          return count;     }      public static void main(string[] args) {         scanner input = new scanner(system.in);         system.out.println("enter keywords: ");         string keyword = input.nextline();         system.out.println("enter essay: ");         string essay = input.nextline();         keywordschecker(essay, keyword);      } 

your code should this:

static int keywordschecker(string shortessay, string keywords) {     int count = 0;     string[] ary = keywords.split(",");      (int = 0; < ary.length; i++) {                      if (shortessay.contains(ary[i])) {             count++;         }     }     return count; }  public static void main(string[] args) {     scanner input = new scanner(system.in);     system.out.println("enter keywords: ");     string keyword = input.nextline();     system.out.println("enter essay: ");     string essay = input.nextline();     system.out.println(keywordschecker(essay, keyword));  } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -