int score = 94;
String sWex="女";
if(score>80)
{if (sWex="女")
{System.out.println("进入女子组决赛");}else{System.out.println("进入男子组决赛");}}else{System.out.println("淘汰");}
public class HelloWorld { public static void main(String[] args) { int score = 94; String sex = "女"; if(score>80){ if(sex=="女"){ System.out.println("进入女子决赛组"); }else{ System.out.println("进入男子决赛组"); } }else{ System.out.println("未能晋级决赛"); } } }
写代码时注意中英文切换,还有if后面的条件语句用的是==而不是=,=是赋值语句。你所犯错误我也经常犯,细心点就好了
用 == 来判断是否相等,而不是用 = 来赋值
单个=号是赋值的意思
首先if里面比较两个值想等用“==”不是“=”
最后输出“淘汰"的括号变成中文输入了。
代码正解
int score = 94;
String sWex="女";
if(score>80)
{if (sWex=="女")
{System.out.println("进入女子组决赛");}
else{System.out.println("进入男子组决赛");}
}
else{System.out.println("淘汰");}
if(sWex==“女”) 不能用=,是赋值,==才是相等。