Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';t似乎将int转换为string并运行我的程序,使其输出330_Java - Fatal编程技术网

Java Can';t似乎将int转换为string并运行我的程序,使其输出330

Java Can';t似乎将int转换为string并运行我的程序,使其输出330,java,Java,我做了一些家庭作业调试,我似乎无法让代码运行。。。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(a

我做了一些家庭作业调试,我似乎无法让代码运行。。。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.
    }

}

有一些错误,但我解决了,下面是答案。非常基本的东西。我希望你能得到它

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.
    }

}
更改
String ageStr=“24年”
字符串ageStr=“24”
int three=“3”
String three=“3”
int-answerYears=年龄+三岁至<代码>内回答年份=年龄+三岁字符串应该可以编译,但我强烈建议您花时间学习这些基础知识