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

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

if Scanner Boolean statement with 2 nextInt()

if Scanner Boolean statement with 2 nextInt()

郎朗坤 2022-05-12 17:18:40
我寫了這段代碼,但是當我的密碼正確時我有問題。請指導我。我是 Java 編碼的新手import java.util.Scanner;public class PasswordProjectQ {    private static Scanner passwordInput;    public static void main(String[] args) {        passwordInput = new Scanner(System.in);        int builtInPassword = 3720118;        System.out.println("Please enter your password:(just integer)");        if(passwordInput.hasNextInt() && passwordInput.nextInt() != builtInPassword) {            System.out.println("You entered the right format \nbut the password is WRONG!");        }else if(passwordInput.hasNextInt() && passwordInput.nextInt() == builtInPassword) {            System.out.println("Thanks,your password is correct");        }else {            System.out.println("WRONG format!");        }    }}
查看完整描述

1 回答

?
慕碼人8056858

TA貢獻1803條經驗 獲得超6個贊

您必須調用一次才能獲取密碼,如下所示hasNextInt():passwordInput.nextInt()


if (passwordInput.hasNextInt()) {

    if (passwordInput.nextInt() != builtInPassword) {

        System.out.println("You entered the right format \nbut the password is WRONG!");

    } else {

        System.out.println("Thanks,your password is correct");

    }

} else {

    System.out.println("WRONG format!");

}


查看完整回答
反對 回復 2022-05-12
  • 1 回答
  • 0 關注
  • 95 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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