在if语句中使用带有字符串的"或"语句

dra*_*a90 -6 java string if-statement

所以我想制作一个代码来对单词进行分类以与短语匹配. catString是用户输入的字符串.我希望它仅在此输入为fire或smoke时才执行其余代码.

这是我遇到的麻烦:

if(catString = "fire" || "smoke" );
Run Code Online (Sandbox Code Playgroud)

hic*_*123 6

你需要重复一遍catString =.但是,您不应该使用==(不是=赋值运算符)来比较字符串.使用.equals().所以这看起来像:

if(catString.equals("fire") || catString.equals("smoke"));
Run Code Online (Sandbox Code Playgroud)