나는 여전히 메서드를 사용하는 방법을 배우고 있지만 도로의 다른 그루터기를 쳤습니다. 다른 정적 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.
나는 심지어 메소드를 호출 할 수없는 매우 바보가 된 기분,하지만 말 그대로 지금은 약 2 시간 동안이 문제에 붙어 있었어요.
int를 사용하는 것 이외의 다른 방법을 '변수'라고 부르는 방법을 알지 못했습니다. 교수님은 int와 double을 사용하는 메소드를 호출하는 방법을 보여 주셨습니다. 그래서 그녀는 반환 값도 얻었습니다. int n 대신에 그것을 호출하는 방법이 있습니까? – Sozziko
당신은 혼란스러운 인수와 반환 값을 가지고 있습니다. 메소드의 인수의 유형과 수는 리턴하는 것과는 아무런 관련이 없습니다. 'int foo()'와'void bar (int i)'를 가질 수 있습니다. 첫 번째 인수는 인수를 취하지 않고 int를 반환합니다. 두 번째 인수는 int를 인수로 취하고 아무 것도 반환하지 않습니다. –