不会交换,JAVA是值传递,在传入swap时x和y的值已经复制给了另外的局部变量,intvalue是值它的整数值,它还有其他的值,比如floatvalue和其他的值.

解决方案 »

  1.   

    不会交换
    楼主的程序里有些错误,我改了下
    intValue()是Integer的方法,它返回Integer中的int值public class ToTest {
      public static void swap (Integer a, Integer b) {
        Integer temp = a;
        a = b;
        b = temp;
      }  public static void main (String[] args) {
        Integer a = new Integer(6);
        Integer b = new Integer(9);
        System.out.println("a :" + a.intValue() + ", b:" + b.intValue());
        swap(a, b);
        System.out.println("a :" + a.intValue() + ", b:" + b.intValue());
      }
    }