public class swap39{ //定义类
public static void main(String[] args){
Integer a=new Integer(10);
Integer b=new Integer(50);
System.out.println("before swap...");
System.out.println("a is "+a);
System.out.println("b is "+b);
swap(a,b);
System.out.println("after swap...");
System.out.println("a is "+a);
System.out.println("b is "+b);
}
public static void swap(Integer pa,Integer pb){
Integer temp=pa;
pa=pb;
pb=temp;
System.out.println("in swap...");
System.out.println("a is "+a);
System.out.println("b is "+b);
}
}
public static void main(String[] args){
Integer a=new Integer(10);
Integer b=new Integer(50);
System.out.println("before swap...");
System.out.println("a is "+a);
System.out.println("b is "+b);
swap(a,b);
System.out.println("after swap...");
System.out.println("a is "+a);
System.out.println("b is "+b);
}
public static void swap(Integer pa,Integer pb){
Integer temp=pa;
pa=pb;
pb=temp;
System.out.println("in swap...");
System.out.println("a is "+a);
System.out.println("b is "+b);
}
}
18:cannot resolve symbol symbol:variable a location: class swap39
System.ou.println("a is "+a^);a是一个对象啊。。难道不能打印出赋值为10的a值吗。。???请指教
类似问题在csdn提出的还是挺多的。搜搜看看?
System.out.println("b is " + b);这两个地方出错,没有定义
Integer a=new Integer(10);
Integer b=new Integer(50); 这不是定义和初始化赋值吗??
Integer temp=pa;
pa=pb;
pb=temp;
System.out.println("in swap...");
System.out.println("a is "+a);
System.out.println("b is "+b);
} 说的是这两个地方没定义
+a,+b,改成+pa,+pb,已正确谢谢。。 太粗心了