為什么輸出為進入男子組決賽?不應該女子組嗎?
public class HelloWorld {
? ? public static void main(String[] args) {
int score = 94;
String sex = "女";
? ? ? ? if(score>80){
? ? ? ? ? ? if(sex.equals('女')){
? ? ? ? ? ? ? ? System.out.println("進入女子組決賽");
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? System.out.println("進入男子組決賽");
? ? ? ? ? ? }
? ? ? ? }else{
? ? ? ? ? ? System.out.println("無法進入決賽");
? ? ? ? }
}
}
2018-11-26
sex = "女"是String字符串,不是char,所以你的條件應該使用雙引號?if(sex.equals("女"))