Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 我得到了一个“答案”;“不兼容类型”;错误就在这里,我不知道为什么_Java_Incompatibletypeerror - Fatal编程技术网

Java 我得到了一个“答案”;“不兼容类型”;错误就在这里,我不知道为什么

Java 我得到了一个“答案”;“不兼容类型”;错误就在这里,我不知道为什么,java,incompatibletypeerror,Java,Incompatibletypeerror,请帮我找到我的代码是“不兼容类型”的地方…我已经找了又找,到处都找不到 import java.util.Scanner; public class Years { private int centuries, decades; public Years(int years) { centuries = years / 100; years -= 25 * years; decades = years / 10;

请帮我找到我的代码是“不兼容类型”的地方…我已经找了又找,到处都找不到

import java.util.Scanner;

public class Years
{
    private int centuries, decades;

    public Years(int years)
    {
        centuries = years / 100;
        years -= 25 * years;
        decades = years / 10;
        years -= 10 * years;
    }
    public int getCenturies()
    {
        return centuries;
    }
    public int getDecades()
    {
        return decades;
    }
    public static void main(String[] args)
    {
        int years;

        if(args.length >= 1)
        {
            years = Integer.parseInt(args[0]);
        }
        else
        {
            Scanner keyboard = new Scanner(System.in);
            System.out.print("Enter the amount in years: ");
            years = keyboard.nextInt();
            keyboard.close();
        }

        Years y = new Years(years);
        System.out.println(years = "y =" + 
        y.getCenturies() + "c +" + y.getDecades() + "d"); // I am getting the error right here.
        }
}
问题是
years=
。编译器并不确定如何处理这个问题。
=
右侧的结果是一个字符串,因为您正在执行字符串串联

因此编译器认为您正在这样做:

years = ("y =" + y.getCenturies() + "c +" + y.getDecades() + "d")
years
是整数,因此这不是有效的表达式

你可能只是想说:

System.out.println(
    "y = " + y.getCenturies() + "c + " + y.getDecades() + "d"
);
或者可能将
年份
连接到其中的某个位置:

System.out.println(
    years + "y = " +
    y.getCenturies() + "c + " + y.getDecades() + "d"
);
问题是
years=
。编译器并不确定如何处理这个问题。
=
右侧的结果是一个字符串,因为您正在执行字符串串联

因此编译器认为您正在这样做:

years = ("y =" + y.getCenturies() + "c +" + y.getDecades() + "d")
years
是整数,因此这不是有效的表达式

你可能只是想说:

System.out.println(
    "y = " + y.getCenturies() + "c + " + y.getDecades() + "d"
);
或者可能将
年份
连接到其中的某个位置:

System.out.println(
    years + "y = " +
    y.getCenturies() + "c + " + y.getDecades() + "d"
);
问题是
years=
。编译器并不确定如何处理这个问题。
=
右侧的结果是一个字符串,因为您正在执行字符串串联

因此编译器认为您正在这样做:

years = ("y =" + y.getCenturies() + "c +" + y.getDecades() + "d")
years
是整数,因此这不是有效的表达式

你可能只是想说:

System.out.println(
    "y = " + y.getCenturies() + "c + " + y.getDecades() + "d"
);
或者可能将
年份
连接到其中的某个位置:

System.out.println(
    years + "y = " +
    y.getCenturies() + "c + " + y.getDecades() + "d"
);
问题是
years=
。编译器并不确定如何处理这个问题。
=
右侧的结果是一个字符串,因为您正在执行字符串串联

因此编译器认为您正在这样做:

years = ("y =" + y.getCenturies() + "c +" + y.getDecades() + "d")
years
是整数,因此这不是有效的表达式

你可能只是想说:

System.out.println(
    "y = " + y.getCenturies() + "c + " + y.getDecades() + "d"
);
或者可能将
年份
连接到其中的某个位置:

System.out.println(
    years + "y = " +
    y.getCenturies() + "c + " + y.getDecades() + "d"
);

你应该把错误放在哪里,而不仅仅是错误本身。我用一个注释来显示错误在哪里……错误在程序的底部。如果你看System.out.println(
years=“y=”
+,这里有一个连接问题,你应该把错误放在哪里,而不仅仅是错误本身。我用一个注释来显示错误在哪里……错误在程序的底部。如果你看System.out.println(
years=“y=”
+,这里有一个连接问题,你应该把错误放在哪里,而不仅仅是错误本身。我用一个注释来显示错误在哪里……错误在程序的底部。如果你看System.out.println(
years=“y=”
+,这里有一个连接问题,你应该把错误放在哪里,而不仅仅是错误本身。我用一条注释来显示错误在哪里……错误在程序的底部。如果你看System.out.println(
years=“y=”
+),这里有一个连接问题