Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
Try this. public static int findPattern(String str, String[] patt) { int count=0; StringTokenizer st = new StringTokenizer(str, " ,.;:"); while (st.hasMoreTokens()) { String tok = st.nextToken(); for (String s: patt) { if (tok.equals(s)) count++; } } return count; } public static void main(String[] args) { String str = "This is a test, the test is simple. You are good."; String[] patt = {"is", "the", "are"}; System.out.println("Pattern count = "+findPattern(str, patt)); }
18th Feb 2017, 4:23 AM
Jian-hua Yeh
Jian-hua Yeh - avatar