최대 입력을 출력으로 가져 오는 함수가있는 클래스를 작성했지만 결과가 잘못되었습니다.최대 계산시 잘못된 결과
public class Test {
public int max(int a, int b) {
if(a > b)
return a;
else {
swap(a, b);
return a;
}
}
private void swap(int a, int b) {
// TODO Auto-generated method stub
int tmp = a;
a = b;
b = tmp;
}
public static void main(String[] args) {
Test t = new Test();
int max = t.max(3, 6);
System.out.println(max);
}
}
내 결과가 3보다는 6
자바 스크립트는 자바하지 않는 프로그램을입니다 얻으려면. – Li357
참고 : http://stackoverflow.com/questions/40480/is-java-pass-by-reference-or-pass-byvalue?rq=1 왜 스왑 방식이 필요합니까? – Li357
나는 a를 원한다 최대 가치 – Jingwei