java - How to Search a string array for specific strings -
i trying search array couple of specific strings words in sentence. sentence in-putted user have hard coded in @ moment make testing easier.if program finds strings should return "yes" , "no" if doesn't. problem getting yes time.
public class main { public static void main(string[]args) { string sentence = "this sentence"; string[] censorlist = {"big","head"}; string[] words = sentence.split(" "); system.out.println(words.length); boolean match = false; for(int = 0; < words.length; i++) { (int j = 0; j < censorlist.length; j++) { if(words[i].equals(censorlist[j])) { match = true; }else{ match = false; } } } if (match = true){ system.out.println("yes");} else{ system.out.println("no"); }
} }
i appreciate one, in advance.
the if in second for() has wrong braces.
try one:
for (int j = 0; j < censorlist.length; j++) { if(words[i].equals (censorlist[j])) { match = true; system.out.println("yes"); } else { system.out.println("no"); } match = false; }
for second try:
the
if (match = true)
does not compare match true, sets match flag true, results in true.
compare flag in if:
if (match == true) // or if (match) { ....