- package cn.itcast.day1;
- public class Practise {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- int a = 3;
- int b = 7;
- System.out.printf("交换前a的值是%d b的值是 %d\n",a,b);
- int c = 0; //定义一个变量存储调换的值
- c = a; //首先把a的值赋值给c 现在c的值就是a的值
- a = b; //把b的值7赋值给a
- b = c; //也就是把原来a的值3赋值给b
- System.out.printf("交换后a的值是%d b的值是 %d",a,b);
-
- }
- }
复制代码 |