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

          常用鏈接

          留言簿(6)

          我參與的團隊

          隨筆分類(88)

          隨筆檔案(92)

          文章分類(142)

          文章檔案(182)

          天基成員

          學(xué)習(xí)園

          我的海角

          搜索

          •  

          積分與排名

          • 積分 - 183507
          • 排名 - 319

          最新評論

          //求平均成績,且無固定人數(shù),
          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("請輸入分數(shù)(-1)結(jié)束: ");
                   score=scanner.nextInt();
                     }
                     System.out.print("平均:"+sum/count);
                   }
                }
                  

          //求平均成績,且有固定人數(shù),
          import java.util.Scanner;
           public class AverageInput{
               public static void main(String[]args){
                   Scanner scanner=new Scanner(System.in);
                   System.out.print("請輸入學(xué)生人數(shù):");
                   int length=scanner.nextInt();//將字符轉(zhuǎn)成整數(shù)
                   float[]score=new float [length];//動態(tài)的配置長度
                   //遍歷成績
                   for(int i=0;i<score.length;i++){
                   System.out.print("請輸入分數(shù) :");
                   float input=scanner.nextFloat();
                   score[i]=input;
                   }
                   System.out.print(""n分數(shù)");
                   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)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 苍山县| 新干县| 象山县| 仙桃市| 江阴市| 沙雅县| 犍为县| 阳泉市| 无棣县| 夏津县| 崇州市| 定西市| 英吉沙县| 当涂县| 淄博市| 古蔺县| 泸溪县| 青神县| 宜黄县| 潜山县| 庆城县| 宁都县| 图片| 东乡族自治县| 水城县| 梁山县| 农安县| 玉田县| 郴州市| 磴口县| 新兴县| 抚顺市| 通江县| 交城县| 金堂县| 汶川县| 九龙县| 古丈县| 错那县| 祥云县| 彭阳县|