我仍在学习使用方法,但我在路上遇到了另一个障碍。我试图在另一个静态 void 方法中调用一个静态 void 方法。所以它大致看起来像这样:
public static void main(String[] args) {
....
}
//Method for total amount of people on earth
//Must call plusPeople in order to add to total amount of people
public static void thePeople (int[][] earth) {
How to call plusPeople?
}
//Method adds people to earth
//newPerson parameter value predefined in another class.
public static void plusPeople (int[][] earth, int newPerson) {
earth = [newPerson][newPerson]
}
我尝试了一些没有真正奏效的不同方法。
int n = plusPeople(earth, newPerson);
//Though I learned newPerson isn't recognized
because it is in a different method.
int n = plusPeople(earth); \
//I don't really understand what the error is saying,
but I'm guessing it has to do with the comparison of these things..[]
int n = plusPeople;
//It doesn't recognize plusPeople as a method at all.
我什至无法调用方法而感到非常愚蠢,但我已经在这个问题上卡住了大约两个小时。