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

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

似乎無法將 int 轉換為字符串并運行我的程序,因此它輸出 330

似乎無法將 int 轉換為字符串并運行我的程序,因此它輸出 330

白豬掌柜的 2023-03-23 16:57:39
我進行了一些調試作業,但似乎無法運行代碼……Java 的新手,希望得到任何反饋public class Errors {    public static void main(String[] args) {        System.out.println("Welcome to my first program!\n");        String ageStr = "24 years";        int age = Integer.parseInt(ageStr);        System.out.println("I'm " + age + " years old.");        int three = "3";        int threeToString = Integer.parseInt(three);        int answerYears = age + three;        System.out.println("Toal number of years: " + answerYears);        int answerMonths = answerYears * 12;        System.out.println("In 3 years and 6 months, I'll be " + answerMonths + " months old");        // Once you've corrected all the errors, the answer should be 330.    }}
查看完整描述

1 回答

?
繁星淼淼

TA貢獻1775條經驗 獲得超11個贊

有一些錯誤,但我解決了,這就是答案。很基本的東西。我希望你能明白。


public class Errors {


    public static void main(String[] args) {


        System.out.println("Welcome to my first program!\n");


        String ageStr = "24";                           //24years is wrong input, enter only 24


        int age = Integer.parseInt(ageStr);


        System.out.println("I'm " + age + " years old.");


        String three = "3";

        int ageToString = Integer.parseInt(ageStr);

        int threeToString = Integer.parseInt(three);

        int answerYears = ageToString + threeToString;


        System.out.println("Toal number of years: " + answerYears);


        int answerMonths = answerYears * 12 + 6;                //you forgot to add 6 months


        System.out.println("In 3 years and 6 months, I'll be " + answerMonths + " months old");


        // Once you've corrected all the errors, the answer should be 330.

    }


}


查看完整回答
反對 回復 2023-03-23
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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