package javaapplication15;
import java.util.Scanner;
public class JavaApplication15 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter your sentence: ");
String message = keyboard.nextLine();
String[] words = {" gray "," better "," formed "," eggs "," made "," cost ",
" decide "," sequence "," crap "," have "," two "," six "};
if(message.toLowerCase().contains(words))
System.out.println("Sentence contains profanity");
else
System.out.println("Sentence does not contain profanity");
}
}
我需要代碼來檢查數組中的單詞。如果句子有胡扯而不是廢話,那麼它就不應該顯示任何褻瀆。我的問題是if
聲明。我試圖用含有數組名稱的單詞來說明一些關於charsequence的內容。需要檢查用戶輸入的褻瀆詞的句子
閱讀此前實施:https://blog.codinghorror.com/obscenity-filters-bad-idea-or-incredibly-intercoursing-bad-idea/和https ://en.wikipedia.org/wiki/Scunthorpe_problem ...和* actual *錯誤信息,而不是「說些什麼」,這很重要。 – ceejayoz
這不適用於'egg.' –
它說String []不能轉換爲charsequence –