- public class TQC107
- {
- public static void main(String[] args)
- {
- if(args.length<2)
- {
- System.out.println("最少需輸入兩個數字");
- return;
- }
- float tot=0;
- for(int i=0;i<args.length;i++)
- {
- tot +=Float.parseFloat(args[i]);
- }
- tot /=args.length;
- switch(Integer.parseInt(args[0]))
- {
- case 0:
- System.out.printf("平均值=%.0f",tot);
- break;
- case 1:
- System.out.printf("平均值=%.1f",tot);
- break;
- case 2:
- System.out.printf("平均值=%.2f",tot);
- break;
- }
- }
- }
複製代碼 |