如何在java

时间:2018-04-02 21:41:30

标签: java arrays types

大家好,我在职业生涯中遇到最艰难的时间。 在这里,我对代码进行了评论,因此很容易发现问题。 我希望有人可以救援我,感谢提前救援人员。 以下代码

public class Marathon {
    /** The whole point here is: how can I return a new arr which is of type Marathon */
    static int [][] raceValues;

    public Marathon(int aValue){
        this.raceValues = [aValue][aValue]; // (Problem no.1) Erroneously accessing a static variable nonstatically
        for (int i = 1; i <= aValue; i++) {
            for (int j = 1; j <= aValue; j++) {
                this.raceValues[i-1][j-1] = (aValue * (i - (aValue - (aValue - 1)))) + j;
            }
        }
    }

    Marathon alterAnyValue(int a){
    /*
    *  If I could write something like next line, then my problem would be solved. But eclipse will grizzle
    *  "Cannot convert from int to Marathon"
    *  Marathon arr[][] = raceValues;
    */
    int arr[][] = raceValues; 
    for (int i = 0; i < aValue; i++) {
        for (int j = 0; j < aValue; j++) {
            int c = arr[i][j] % 3; // Divisible by three
            int d = arr[i][j] % 5;  // Divisible by five
            if(c == 0){
                arr[i][j] = 3;
            }

            if(d == 0){
                arr[i][j] == 5;
            }
        }
    }
    /*
    * Here I don't know how to return new arr
    * I must return a new arr and it must be of type Maraton
    * At this point the whole world just ended. I don't know what to do
    */
    //return new Marathon()
    //return arr
    }
}

1 个答案:

答案 0 :(得分:-1)

对于您的第一个问题:静态访问:您可以执行${IMAGE_ROOTFS}这将解决您的静态访问“错误”

对于你的第二个问题,我没有看到Java的可能性,因为你不能创建新的“整数”类,因为它们是最终的。你可以制作自己的整数,但我无法想象为什么。所以另一种可能是你返回一个整数数组。

这将是我想要做的。如果你想要不同的东西,请更好地指出问题:)