隨筆 - 64  文章 - 9  trackbacks - 0
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(6)

          我參與的團隊

          隨筆分類(88)

          隨筆檔案(92)

          文章分類(142)

          文章檔案(182)

          天基成員

          學習園

          我的海角

          搜索

          •  

          積分與排名

          • 積分 - 183418
          • 排名 - 319

          最新評論

          //求平均成績,且無固定人數,
          import java.util.Scanner;
           public class ScoreAverage{
               public static void main(String[]args){
                   Scanner scanner=new Scanner(System.in);
                   int score=0;
                   int sum=0;
                   int count=-1;
                   while(score!=-1){
                       count++;
                       sum=sum+score;
                   System.out.print("請輸入分數(-1)結束: ");
                   score=scanner.nextInt();
                     }
                     System.out.print("平均:"+sum/count);
                   }
                }
                  

          //求平均成績,且有固定人數,
          import java.util.Scanner;
           public class AverageInput{
               public static void main(String[]args){
                   Scanner scanner=new Scanner(System.in);
                   System.out.print("請輸入學生人數:");
                   int length=scanner.nextInt();//將字符轉成整數
                   float[]score=new float [length];//動態的配置長度
                   //遍歷成績
                   for(int i=0;i<score.length;i++){
                   System.out.print("請輸入分數 :");
                   float input=scanner.nextFloat();
                   score[i]=input;
                   }
                   System.out.print(""n分數");
                   float total=0;
              for(int i=0;i<score.length;i++){
              total=total+score[i];
              System.out.print(score[i]+" ");
              }
              System.out.printf(""n平均:%.2f",total/score.length);//.2f精度為二位
              }
             }
              
          posted on 2009-03-23 20:58 鵬凌 閱讀(126) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 北川| 寻乌县| 利津县| 克什克腾旗| 三门峡市| 鸡西市| 灵台县| 吴桥县| 东平县| 南岸区| 永仁县| 临城县| 库伦旗| 察哈| 富锦市| 徐水县| 沐川县| 治县。| 三门县| 西乌珠穆沁旗| 平乐县| 万载县| 涞水县| 尼玛县| 樟树市| 兰州市| 武平县| 贡山| 新安县| 肥乡县| 望江县| 盐源县| 翼城县| 屏南县| 茂名市| 青龙| 应用必备| 长丰县| 乌拉特后旗| 沁水县| 苍南县|