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 ...そして、実際のエラーメッセージは、「何かについて」は重要ではないでしょう。 – ceejayoz
これは 'eggs.'のためにはうまくいかないでしょう –
String []は文字列に変換できません –