I’m still learning to use methods, but I hit another stump in the road. I’m trying to call a static void method in another static void method. So it roughly looks like this:
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]
}
I’ve tried a few different things which hasn’t really worked.
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.
I feel very stupid for not being able to even call a method, but I’ve literally been stuck on this issue for about two hours now.
You need to provide two arguments. The first one needs to be of type
int[][](andearthqualifies), and the second one needs to be an int. So, for example:Of course, that’s only a technical answer. What you should really pass as argument depends on what the method does with its arguments (which should be specified in its javadoc), what the arguments mean (which should be specified in its javadoc), and what you want the method to do for you (which you should know).
Also, note that since the method is declared as
void plusPeople(...), it doesn’t return anything. So doingint n = plusPeople(earth, newPerson);doesn’t make any sense.