返回列表 發帖
  1. public class TQC107 {

  2.         /**
  3.          * @param args
  4.          */
  5.         public static void main(String[] args) {
  6.                 // TODO Auto-generated method stub
  7.                 if(args.length<2)
  8.                 {
  9.                         System.out.println("最少需輸入兩個數字");
  10.                         return;
  11.                 }
  12.                 float tot=0;
  13.                 for(int i=0;i<args.length;i++)
  14.                 {
  15.                         tot +=Float.parseFloat(args[i]);
  16.                 }
  17.                 tot /=args.length;
  18.                 switch(Integer.parseInt(args[0]))
  19.                 {
  20.                         case 0:
  21.                         System.out.printf("平均值=%.0f",tot);
  22.                         break;
  23.                         case 1:
  24.                         System.out.printf("平均值=%.1f",tot);
  25.                         break;
  26.                         case 2:
  27.                         System.out.printf("平均值=%.2f",tot);
  28.                         break;
  29.                 }
  30.         }

  31. }
複製代碼
★ 嘉凱~~☆

TOP

返回列表