你不一定做得出来额!不行就来试试。 我们定义了两个整型变量X和Y;我们把X和Y的值分别赋于为3和4,我们的要求是不借助任何其他的变量,把X和Y的值交换,即把X的值变为4,而Y的值变为3.试一试吧!希望你做出来额!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int x = 3;int y = 4; x = x+y; //7 y = x-y;//3 x = x-y;// 4 int x=3;int y=4;x=(y^x^(y=x)); public class Test2009041302 { public static void main(String[] args) { Test2009041302 test=new Test2009041302(); test.changValue(3, 4); } public void changValue(int x,int y){ System.out.println("换值之前:x="+x+"\ty="+y); y=y-x; x=x+y; y=x-y; System.out.println("换值之后:x="+x+"\ty="+y); }} int x = 3; int y = 4; x = x+y; y = x-y; x = x-y; int x=3;int y=4; x=x^y; y=y^x; x=x^y; 这样也行吧int x = 3;int y = 4;x = 4;y = 3;System.out.println(x);System.out.println(y); int x = 3; int y = 4; x = x+y; y = x-y; x = x-y; int a=1,b=2;a=a+b;b=a-b;a=a-b;System.out.printf("a=%d,b=%d",a,b); 提问前先gg一下吧。可读性好的算术运算,支持所有整型常量的位运算,都能达到目的.c/c++里还有支持浮点数、结构体和类对象交换的指针运算 算法题:比较字符串是否相等 JAVA 课程设计.《题目:排球比赛计分系统》求帮助! mysql插入图片文件问题 JAVA的一个入门问题 @Action 是什么意思? 关于无参构造函数的问题,请大伙帮我分析一下 编译时classpath问题,莫名其妙,在线等 applet和ie的tips有冲突.怎么办.也就是有applet页面存在的时候 ie或其他页面上的tips得不到显示 各位老大帮忙,什么是JavaBeans呀! 学java的不别人傲么? 关于使用eclipse创建包的一些问题? 关于 这道题的算法
int y = 4;
x = x+y; //7
y = x-y;//3
x = x-y;// 4
public class Test2009041302 {
public static void main(String[] args) {
Test2009041302 test=new Test2009041302();
test.changValue(3, 4);
}
public void changValue(int x,int y){
System.out.println("换值之前:x="+x+"\ty="+y);
y=y-x;
x=x+y;
y=x-y;
System.out.println("换值之后:x="+x+"\ty="+y);
}
}
int y = 4;
x = x+y;
y = x-y;
x = x-y;
int y=4;
x=x^y;
y=y^x;
x=x^y;
int x = 3;
int y = 4;
x = 4;
y = 3;
System.out.println(x);
System.out.println(y);
int y = 4;
x = x+y;
y = x-y;
x = x-y;
int a=1,b=2;
a=a+b;
b=a-b;
a=a-b;
System.out.printf("a=%d,b=%d",a,b);
可读性好的算术运算,
支持所有整型常量的位运算,
都能达到目的.
c/c++里还有支持浮点数、结构体和类对象交换的指针运算