第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

BJP4 練習(xí) 3.20: 輸入出生日期

BJP4 練習(xí) 3.20: 輸入出生日期

慕妹3146593 2022-08-03 16:18:09
編寫一個(gè)名為 inputBirthday 的方法,該方法接受控制臺(tái)的掃描儀作為參數(shù),并提示用戶輸入出生月份、日期和年份,然后以合適的格式打印出生日期。下面是與用戶的對(duì)話示例:我需要像這樣接受這個(gè)輸入 -你出生在一個(gè)月中的哪一天?8你出生的月份叫什么名字?五月你出生在哪一年?1981輸出應(yīng)該是這樣的——您出生于1981年5月8日。你老了!
查看完整描述

3 回答

?
料青山看我應(yīng)如是

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊

public static void inputBirthday(Scanner input) {

     Scanner start = new Scanner(System.in);

    System.out.print("On what day of the month were you born? ");

    int day = input.nextInt();

    System.out.print("What is the name of the month in which you were born? ");

    String month = input.next();

    System.out.print("During what year were you born? ");

    int year = input.nextInt();

     System.out.println("You were born on " + month + " " + day + "," + " " + year + "." + " You're mighty old!");

}


查看完整回答
反對(duì) 回復(fù) 2022-08-03
?
牛魔王的故事

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊

public static void main(String[] args) {


    Scanner in = new Scanner(System.in);

    // either instantiate the enclosing class, or make inputBirthday static

    inputBirthday(in);

    }


  public static void inputBirthday(Scanner abc)

 {

    System.out.print("On what day of the month were you born? ");

    int inputDay = abc.nextInt();

    System.out.print("What is the name of the month in which you were born? ");

    String inputMonth = abc.next();

    System.out.print("During what year were you born? ");

    int inputYear = abc.nextInt();

    System.out.println("You were born on " + inputMonth + " " + inputDay + "," + " " + inputYear + "." + " You're mighty old!");

    }

最后它工作了,代碼通過(guò)了所有測(cè)試


查看完整回答
反對(duì) 回復(fù) 2022-08-03
?
米脂

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超3個(gè)贊

我認(rèn)為問(wèn)題在于,要求明確規(guī)定你要編寫一個(gè)名為接受對(duì)象的方法。您已經(jīng)編寫了一個(gè)方法,然后編寫了一個(gè)正在接受 的方法。inputBirthdayScannermaininputBirthdayString, int, int


將代碼從方法移動(dòng)到方法,刪除掃描儀實(shí)例化,并修改方法以接受掃描儀(可能是 .maininputBirthdayinputBirthdayinputBirthday(Scanner abc)


編寫的代碼在 intellij 中工作,因?yàn)樗且粋€(gè)完整的程序。但對(duì)于網(wǎng)站,他們希望有一個(gè)特定的方法簽名。這種方法與此類在線代碼位置所期望的沒(méi)有什么不同。leetcode


OP進(jìn)行了編輯,但同樣,要求規(guī)定該方法應(yīng)如下所示:


public void inputBirthday(Scanner abc) {

    System.out.println("On what day of the month were you born? ");

    int inputDay = abc.nextInt();

    System.out.println("What is the name of the month in which you were born? ");

    String inputMonth = abc.next();

    System.out.println("During what year were you born? ");

    int inputYear = abc.nextInt();

    System.out.println("You were born on " + inputMonth + " " + inputDay + "," + " " + inputYear + "." + " You're mighty old!");

}

所以,再次:


獲取方法簽名以匹配要求(不清楚它是否應(yīng)該是靜態(tài)的,因此可能需要是)。public static inputBirthday(Scanner abc)

不要在方法中實(shí)例化掃描儀。inputBirthday

要從 IDE 進(jìn)行測(cè)試,請(qǐng)執(zhí)行以下操作:


public static void main(String[] args) {

  Scanner in = new Scanner(System.in);

  // either instantiate the enclosing class, or make inputBirthday static

  inputBirthday(in);

}


查看完整回答
反對(duì) 回復(fù) 2022-08-03
  • 3 回答
  • 0 關(guān)注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)