- public class example{
- public static void main(String args[]){
- int a=9,b=5,c=7,t=0;
- if(b<a){//true
- t=a;// t = 9
- a=b;//a = 5
- b=a;// b = 5,a = 5,t = 9
- }
- if(c<a){//false,不执行 c = 7 ,a = 5
- t=a;
- a=c;
- c=t;
- }
- if(c<b){//false,不执行 c = 7, b =5
- t=b;
- b=c;
- c=t;
- }
- System.out.println("a,b,c从小到大排列:"+a+","+b+","+c);
- }
- }
复制代码 |