Java //手動輸入3個數,並從小到大排序


 1  //手動輸入3個數,並從小到大排序
 2         //import java.util.Sanner;
 3        
 4         System.out.println("請輸入第一個數:");
 5         Scanner sc = new Scanner(System.in);
 6         int upSort1 = sc.nextInt();
 7         System.out.println("upSort1 = "+upSort1);
 8         
 9         System.out.println("請輸入第二個數:");
10         int upSort2 = sc.nextInt();
11         System.out.println("upSort2 = "+upSort2);
12        
13         System.out.println("請輸入第三個數:");
14         int upSort3 = sc.nextInt();
15         System.out.println("upSort3 = "+upSort3);
16         
17         
18         if(upSort1 >=upSort2 )
19         {
20             if(upSort1 <= upSort3)
21             {
22                 System.out.println(upSort2+","+upSort1+","+upSort3);
23             }
24             else if(upSort3 <= upSort2) 
25             {
26                 System.out.println(upSort3+","+upSort2+","+upSort1);
27             }
28             else
29             {
30                 System.out.println(upSort2+","+upSort3+","+upSort1);
31             }
32             
33         }
34         else
35         {
36             if(upSort2<=upSort3)
37             {
38                 System.out.println(upSort1+","+upSort2+","+upSort3);
39             }
40             else if(upSort1>= upSort3)
41             {
42                 System.out.println(upSort3+","+upSort1+","+upSort2);
43             }
44             else
45             {
46                 System.out.println(upSort1+","+upSort3+","+upSort2);
47             }
48         }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM