三个数排序
/**
最經典的C語言算法!
*/
public class 第十五題三個數排序 {public static void main(String[] args) {Scanner in = new Scanner(System.in);System.out.print("請輸入三個整數: ");int a = in.nextInt();int b = in.nextInt();int c = in.nextInt();int temp = 0;//首先如果 a > b,那么把a和b的值互換,變成了 a < bif(a > b) {temp = a;a = b;b = temp; }//其次如果a > c,那么把a和c的值互換,變成了a < cif(a > c) {temp = a;a = c;c = temp; }//最后如果b > c,那么把b和c的值互換,變成了b < c,此時就能確定a < b < c,排序完成if(b > c) {temp = b;b = c;c = temp;}System.out.println("按照升序排序:" + a + " " + b + " " + c); // System.out.println("按照降序排序:" + c + " " + b + " " + a); in.close();} }
最經典的C語言算法!
*/
public class 第十五題三個數排序 {public static void main(String[] args) {Scanner in = new Scanner(System.in);System.out.print("請輸入三個整數: ");int a = in.nextInt();int b = in.nextInt();int c = in.nextInt();int temp = 0;//首先如果 a > b,那么把a和b的值互換,變成了 a < bif(a > b) {temp = a;a = b;b = temp; }//其次如果a > c,那么把a和c的值互換,變成了a < cif(a > c) {temp = a;a = c;c = temp; }//最后如果b > c,那么把b和c的值互換,變成了b < c,此時就能確定a < b < c,排序完成if(b > c) {temp = b;b = c;c = temp;}System.out.println("按照升序排序:" + a + " " + b + " " + c); // System.out.println("按照降序排序:" + c + " " + b + " " + a); in.close();} }
?
轉載于:https://www.cnblogs.com/zjulanjian/p/10952669.html
總結
- 上一篇: NPOI导出excel
- 下一篇: 一队老耗子,每个月都生一对小耗子,小耗子