在 Java 应用程序中如何编写一个方法来交换两个基本类型的值或两个对象引用的值呢? 50
展开全部
int a = 10;
int b = 20;
public void changebasicvalue(int a,int b){//基本类型值的交换
int c = a;
a = b;
b = c;
System.out.println("a="+a + " b="+b);
}
String m = "aaaaa";
String n = "bbbbb";
public void changeObject(Object m,Object n){//仅拷贝对象引用
Object temp = m;
m = n;
n = temp;
}
public void copyConten(Object m,Object n){//拷贝整个对象或者叫克隆
Object temp = m.clone();
m = (Object)n.clone();
n = (Object)temp.clone();
}
int b = 20;
public void changebasicvalue(int a,int b){//基本类型值的交换
int c = a;
a = b;
b = c;
System.out.println("a="+a + " b="+b);
}
String m = "aaaaa";
String n = "bbbbb";
public void changeObject(Object m,Object n){//仅拷贝对象引用
Object temp = m;
m = n;
n = temp;
}
public void copyConten(Object m,Object n){//拷贝整个对象或者叫克隆
Object temp = m.clone();
m = (Object)n.clone();
n = (Object)temp.clone();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2006-10-01
展开全部
int temp;
int number1=1;
int number2=2;
System.out.println("number1="+number1+" number2="+number2);
temp=number1;
number1=number2;
number2=temp;
System.out.println("number1="+number1+" number2="+number2);
int number1=1;
int number2=2;
System.out.println("number1="+number1+" number2="+number2);
temp=number1;
number1=number2;
number2=temp;
System.out.println("number1="+number1+" number2="+number2);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |