請問我這樣寫和標(biāo)準(zhǔn)答案有什么差距
public class HelloWorld {
? ? public static void main(String[] args) {
int score = 94;
String sex = "女";
if(score>80)
{
? ? if(sex=="男")
? ? {
? ? ? ? System.out.println("分配進(jìn)男子組");
? ? }
? ? else
? ? {
? ? ? ? System.out.println("分配進(jìn)女子組");
? ? }
}
else
{
? ? System.out.println("不能參加決賽");
}
}
}
2019-12-24
當(dāng)sex不為男也不為女的時(shí)候 ,譬如sex為“xxx”且分?jǐn)?shù)大于80的時(shí)候,仍然會被歸到女子組
2020-01-16
String定義的變量為引用類型
==可用于判定數(shù)字類型和引用類型
所以==是可行的
2019-12-25
sex定義的是string類型,用equals來判定是否相同,== 一般是判定數(shù)字類型的吧