亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

if 條件被忽略

if 條件被忽略

互換的青春 2023-05-10 13:45:11
這段代碼應該檢查密碼長度是否合適,但如果密碼長度大于或等于 16,它會跳過 if 條件并且不打印句子。/* This bit of the coe just checks the length of the password */if (Password.length() >= 8) {    if (Password.length() <= 10) {        System.out.println("Medium length of password");    }}else if (Password.length() < 8) {    System.out.println("Bruv youre asking to be hacked");} else if (i >= 10) {    if (Password.length() <= 13) {        System.out.println("Good password length");    }    /* The part that fails */    else if (Password.length() >= 16) {        System.out.println("Great password length");    }        } 如果密碼長度大于或等于 16,則代碼應輸出“Great password length”,但如果密碼長度大于或等于 16,則不會輸出任何內容
查看完整描述

2 回答

?
汪汪一只貓

TA貢獻1898條經驗 獲得超8個贊

if(Password.length() >= 8)并else if(Password.length() < 8)覆蓋所有可能的密碼長度,因此永遠不會達到以下條件。


你應該以一種不那么混亂的方式組織你的條件:


if (Password.length() < 8) {

    System.out.println("Bruv youre asking to be hacked");

} else if (Password.length() >= 8 && Password.length() <= 10) {

    System.out.println("Medium length of password");

} else if (Password.length() > 10 and Password.length() <= 13) {

    System.out.println("Good password length");

} else if (Password.length() > 13 && Password.length() < 16) {

    ... // you might want to output something for passwords of length between 13 and 16

} else {

    System.out.println("Great password length");

}

甚至更好


if (Password.length() < 8) {

    System.out.println("Bruv youre asking to be hacked");

} else if (Password.length() <= 10) {

    System.out.println("Medium length of password");

} else if (Password.length() <= 13) {

    System.out.println("Good password length");

} else if (Password.length() < 16) {

    ... // you might want to output something for passwords of length between 13 and 16

} else {

    System.out.println("Great password length");

}


查看完整回答
反對 回復 2023-05-10
?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

嘗試使用:


if (Password.length() >= 8) {

    if (Password.length() <= 10) {

        System.out.println("Medium length of password");

    } else if (Password.length() <= 13) {

        System.out.println("Good password length");

    } else if (Password.length() >= 16) {

        System.out.println("Great password length");

    }

} else if (Password.length() < 8) {

    System.out.println("Bruv youre asking to be hacked");

}


查看完整回答
反對 回復 2023-05-10
  • 2 回答
  • 0 關注
  • 158 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號