Java에서 호출하는 함수에서 둘 이상의 기본 변수의 누적 합계를 얻는 방법은 무엇입니까? 추가 작업을 위해 다른 방법을 사용하고 싶습니다. 하지만 Java로 값을 기준으로 원시 타입을 전달할 때 어떻게해야합니까?Java - 호출 방법의 누적 합계 - 값/참조을 통한 호출
public void methodA(){
int totalA = 0;
int totalB = 0;
Car aCar = getCar() ; //returns a car object with 2 int memebers a & b
methodB(aCar);
methodB(bCar);
methodB(cCar);
sysout(totalA); // should print the sum total of A's from aCar, bCar and cCar
sysout(totalB); // should print the sum total of b's from aCar, bCar and cCar
}
private methodB(aCar){
totalA += aCar.getA();
totalB += aCar.getB();
}
가능한 중복 : http://stackoverflow.com/questions/2832472/how-to-return-2-values-from-a-java-function – 757071
자바는 "참조에 의해 호출을"이 없습니다 ..하지만이 표시/시뮬레이션하려고하지 않습니다. –