多重循環(huán)問題
public class Shuibian {
?public static void main(String[] args) {
?String today="周末";
?String weather="晴朗";
?
?if(today.equals(today)){
??if(today.equals(weather)){
???System.out.println("室外游玩");
??}else{
???System.out.println("室內(nèi)游玩");
??}
?}else{
??System.out.println("工作");
?}
????
???????
?}
為何運行結(jié)果是室內(nèi)游玩呢?這樣寫不對嗎?
2016-10-24
你的today本來定義為周末,第一個判斷if就是正確的,跳入。在第二個判斷,today為周末,weather為晴朗,不相同,則第二個判斷錯誤,跳入else,輸出室內(nèi)游玩。
2016-10-24
是想從外部輸入,進行判斷嗎?是的話,就要修改代碼了
2016-10-24
第二個if語句中的條件代碼不對,應(yīng)該寫成if(weather.equals(weather))
2016-10-24
一個today判斷,一個weather判斷
2016-10-24
public class jj {?
public static void main(String[] args) {
String today="周末";
String weather="晴朗";
?
if(today.equals("周末")){
?if(weather.equals("晴朗")){
? System.out.println("室外游玩");
?}else{
? System.out.println("室內(nèi)游玩");
?}
}else{
?System.out.println("工作");
}
? ??
? ? ? ?
}
}