java输入三个数从小到大排列输出
使用最基本的方法排列三个数,注意不使用数组 只是用if 赋值 关系运算 或者函数 赋值
操作方法
- 01
使用if 关系运算 赋值
- 02
int a , b , c , max , middle , min ; a = Integer.parseInt(args [0]); b = Integer.parseInt(args [1]); c = Integer.parseInt(args [2]); max = a; if(b > a && b > c ){ max = b; } if(c > a && c > b){ max = c; } min = a; if(b < a && b < c){ min = b; } if(c < a && c < b){ min = c; } middle = (a + b + c) - (max + min); System.out.println(min + ","+ middle + "," + max);
- 03
使用函数 赋值
- 04
int a , b , c , max , middle , min ; a = Integer.parseInt(args [0]); b = Integer.parseInt(args [1]); c = Integer.parseInt(args [2]); max = Math.max(a , b); max = Math.max(max , c); min = Math.min(a , b); min = Math.min(min , c); middle = (a + b + c) - (max + min); System.out.println(min + ","+ middle + "," + max);