小明左手一张10 右手一张8 要互换手中的牌。2个整数分别保存在两个变量中,将这两个变量的直互换,打印输出互换后的结果!
解决方案 »
- 最近初学Swing做功能的时候遇到的问题,希望能帮忙解决下。
- 求一个能在Jtable中实现checkbox的工具类
- 2本关于 Eclipse 的书不知道买那本好,大家帮忙看看。
- 请问如何控制布局器中的加入控制的大小?
- 高分求教,tomcat中各个目录都是干什么用的?
- 我为什么可以改变final数据
- 求助,applet问题。
- 我还没学JAVA呢,想问一下,用哪个集成环境较好?
- 菜鸟问题:想依次打印出b1,b2,b3,b4的值:1、2、3、4
- 求高手解答一个“socket系统部署”的解决方案提供。
- 然后清空一个数组对象 如:Player player[]...
- forgetIt()这个函数有什么功能?
private int c;
c = b;
b = a;
a = c;
System.out,println(a+"\n"+b);
}
public class Test1Server {
public static void main(String[] args) {
Test1Server test = new Test1Server();
test.exchange(10, 8);
}
void exchange(int leftHand,int rightHand ){
int x ;
x = leftHand;
leftHand = rightHand;
rightHand = x;
System.out.print(leftHand);
System.out.print(rightHand);
}
}
b = a-b;
a -= b;
有溢出危险。
b = a;
a = c;
public void exchange(int a,int b){
a ^= b;
b ^= a;
a ^= a;
System.out.println( a + "\n" + b );
}没有溢出危险
public class StudentHome {
int leftHand, rightHand;
StudentHome(int leftHand, int rightHand){
this.leftHand = leftHand;
this.rightHand = rightHand;
System.out.println("Before: leftHand=" + leftHand + " rightHand=" + rightHand);
}
public void exchange() {
this.leftHand = this.leftHand ^ this.rightHand;
this.rightHand = this.rightHand ^ this.leftHand;
this.leftHand = this.leftHand ^ this.rightHand;
System.out.println("After: leftHand=" + leftHand + " rightHand=" + rightHand);
}
public static void main(String args[]) {
StudentHome xiaoming = new StudentHome(10,8);
xiaoming.exchange();
}
}不知道是不是楼主要的
a ^= b;
b ^= a;
a = a^b;
System.out.println( a + "\n" + b );
}
System.out.println("" + left + right);
int temp = left;
left = right;
right = temp;
System.out.println("" + left + right);
}
b = a;
a = c;
这个最简单 也最容易理解了 尤其刚入门的
{
public static void main ( String [] args )
{
int a = 8 ;
int b = 10 ;
int c = 0 ;
System.out.println("小明现在左手的是" + a);
System.out.println("小明现在you手的是" + b);
c = b;
b = a;
a = c;
System.out.println("小明现在左手的是" + b);
System.out.println("小明现在有手的是" + a);
}
}这应该是最简单的了吧
public static void main(String[] args) {
int x ,leftHand=10,rightHand=8;
x = leftHand;
leftHand = rightHand;
rightHand = x;
System.out.print(leftHand);
System.out.print(rightHand);
}
}