java声明的初始化中的长数组失败

java声明的初始化中的长数组失败,java,arrays,variables,multidimensional-array,initialization,Java,Arrays,Variables,Multidimensional Array,Initialization,在以下程序中: public static long Coinsum(int euro) { double[] coins= {0,0.01,0.02,0.05,0.1,0.2,0.5,1,2}; long numberoftimes[][]; for(int i=0;i<coins.length;i++){ for(int j=0;j<=euro;j++) { if(i==0 &&j==0){

在以下程序中:

public static long Coinsum(int euro) {
    double[] coins= {0,0.01,0.02,0.05,0.1,0.2,0.5,1,2};
    long numberoftimes[][];

    for(int i=0;i<coins.length;i++){
        for(int j=0;j<=euro;j++) {
            if(i==0 &&j==0){
                numberoftimes[i][j]=1;
            }
            else if(i<j){
                numberoftimes[i][j]=numberoftimes[i-1][j]+numberoftimes[i][j-i];
            }
            else {
                numberoftimes[i][j]=numberoftimes[i-1][j];
            }
        }
    }
    return numberoftimes[coins.length-1][euro];
}
public静态长币金额(整数欧元){
双[]币={0,0.01,0.02,0.05,0.1,0.2,0.5,1,2};
长次数[];

对于(inti=0;i您需要
new
a
long[][]
。它可以是锯齿状的(但不在这里)。第一个维度是
coins.length
,第二个维度是
euro+1
。Java命名约定是小写的首字母。无论如何,它可能看起来像

public static long coinSum(int euro) {
    double[] coins = { 0, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2 };
    long[][] numberoftimes = new long[coins.length][];

    for (int i = 0; i < coins.length; i++) {
        numberoftimes[i] = new long[euro + 1];
        for (int j = 0; j <= euro; j++) {
            if (i == 0 && j == 0) {
                numberoftimes[i][j] = 1;
            } else if (i < j) {
                numberoftimes[i][j] = numberoftimes[i - 1][j] + numberoftimes[i][j - i];
            } else {
                numberoftimes[i][j] = numberoftimes[i - 1][j];
            }
        }
    }
    return numberoftimes[coins.length - 1][euro];
}
public静态长币金额(整数欧元){
双[]币={0,0.01,0.02,0.05,0.1,0.2,0.5,1,2};
long[]numberoftimes=新的long[coins.length][];
for(int i=0;i对于(int j=0;j它应该是
long numberoftimes[]][]=new long[coins.length][euro+1];

如果你能用问题陈述更新你的问题就好了。你的代码想做什么?这段代码几乎肯定会在运行时崩溃,因为你从来没有初始化过
numberoftimes[]
。您需要类似于
long numberoftimes[][]=new long[10][10]
完全按照警告所说的去做:初始化numberoftimes哦,对不起,这里有新的……这是换硬币的问题……它需要返回可以用来制造一定数量的钱的可能组合的数量。在我的情况下,欧元是钱的数量,硬币是我必须制造所有可能组合的硬币。如果有什么事情发生了esnt有意义让我知道…我是希腊人,所以我的英语没有经过完善的编辑以改进代码格式和语法
j谢谢它现在运行,但由于我的教授制作了一个软件包,它自动检查我们的代码对于特定任务是否正确,我的代码显示它是错误的..问题是我认为我的代码是正确的..我们的教授ssor希望它返回可能的组合数,以使用我们拥有的硬币使欧元可变。。。