基本的に私はしました:あなたは、私はその後、私は,(space)
で各単語を分割していた後、私はif()
を使用して、Action, Animation, Comdey
を含む文字列genre
を持って見ることができるようには、Javaでの単語内の単語を比較
public static void main(String[] args)
{
String genre = "Action, Animation, Comdey";
String[] genres = genre.split(", ");
for(int i=0;i<(genres.length)-1;i++){
System.out.println(genres[i]);
if(!genres[i].equals("Action") || !genres[i].equals("Adventure")
|| !genres[i].equals("Animation") || !genres[i].equals("Biography")
|| !genres[i].equals("Comedy") || !genres[i].equals("Crime")
|| !genres[i].equals("Documentary") || !genres[i].equals("Drama")
|| !genres[i].equals("Family") || !genres[i].equals("Fantasy")
|| !genres[i].equals("Film-Noir") || !genres[i].equals("Game-Show")
|| !genres[i].equals("History") || !genres[i].equals("Horror")
|| !genres[i].equals("Music") || !genres[i].equals("Musical")
|| !genres[i].equals("Mystery") || !genres[i].equals("News")
|| !genres[i].equals("Reality-TV") || !genres[i].equals("Sci-Fi")
|| !genres[i].equals("Sport") || !genres[i].equals("Talk-Show")
|| !genres[i].equals("Thriller") || !genres[i].equals("War")
|| !genres[i].equals("Western")
){
System.out.println("Selected genres could not be identified");
return;
}else {
System.out.println("Success");
}
}
}
各アレイを比較する。あなたはAction
、Animation
とComedy
私のif()
単語リストに存在する私の配列を知っているかもしれません。だから、System.out.println("Selected genres could not be identified");
を実行するとは思わないが、私はなぜそれが本当に私を驚かせているのかわからない。
https://www.compilejava.net/に自分のコードをコピーして貼り付けて、結果を自分で見ることができます。
私が間違っていることを教えていただければ、本当に感謝しています。
代わりに '!'演算子を削除できませんでしたか? –
@Abhijithは '!'を取り除こうとしましたが、質問でOPによって言及されたものと同じ出力を生成します。 –
@ darshanMehtaこれは、私が何を間違えているのか理解しようと一日を浪費したことを意味します。 –