public class study{
public static void main(String[] args) {
int a=1;
int b=3;
exchange(...);
System.out.printf("%d %d",a,b);
}
public void exchange(...) {
...
}
}
大概像这样吧。exchange()的参数和方法体应该怎么写?
改为Integer,基本类型传递形参是传值而非地址引用
exchange(a,b);
{
int temp = a;
a = b;
b = temp;
}