1. <ul id="0c1fb"></ul>

      <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
      <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区

      RELATEED CONSULTING
      相關咨詢
      選擇下列產品馬上在線溝通
      服務時間:8:30-17:00
      你可能遇到了下面的問題
      關閉右側工具欄

      新聞中心

      這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
      java平均分總分代碼 java均分算法

      JAVA代碼問題!輸入5名學生的成績,并計算總成績,平均分,最高分,最低分

      public static void main(String[] args) {

      成都創(chuàng)新互聯(lián)公司作為成都網(wǎng)站建設公司,專注成都網(wǎng)站建設公司、網(wǎng)站設計,有關成都定制網(wǎng)站方案、改版、費用等問題,行業(yè)涉及砂巖浮雕等多個領域,已為上千家企業(yè)服務,得到了客戶的尊重與認可。

      double scores[] = new double[5];

      double total = 0;

      double avg = 0;

      double max = 0;

      double min = 0;

      int count=0;

      String inputStr=null;

      System.out.println("請輸入5名學生的成績:");

      Scanner input = new Scanner(System.in);

      while(count5){

      try{

      if(count 5){

      System.out.println("請輸入第"+(count+1)+"個分數(shù):");

      }

      inputStr=input.nextLine();

      scores[count++]=Double.valueOf(inputStr.trim());

      }catch(Exception e){

      if(inputStr!=null "exit".equals(inputStr.trim())){

      System.out.println("您已成功結束程序");

      System.exit(0);

      }

      System.out.println("若想結束請輸入:exit");

      System.out.print("您輸入的分數(shù)不是數(shù)值類型,");

      count--;

      }

      }

      input.close();

      Arrays.sort(scores);

      min=scores[0];

      max=scores[scores.length-1];

      for(double score :scores){

      total += score;

      }

      avg=total/scores.length;

      System.out.println("總成績是" + total);

      System.out.println("最高分是" + max);

      System.out.println("最低分是" + min);

      System.out.println("平均分是" + avg);

      }

      //-------------------------------------------------------------------------

      public static void main(String[] args) {

      Scanner input = new Scanner(System.in);

      while(true){

      Double[] scores = null;

      double total = 0;

      double avg = 0;

      double max = 0;

      double min = 0;

      int count=1;

      ListDouble inputScores=new ArrayListDouble();

      String inputStr=null;

      System.out.println("請輸入要統(tǒng)計學生的成績(理論上可以輸入無限個,前提是你有那么大的內存):");

      while(true){

      try{

      System.out.println("請輸入第"+count+++"個分數(shù),或輸入ok進行計算,離開請輸入exit");

      inputStr=input.nextLine();

      inputScores.add((double)Double.valueOf(inputStr.trim()));

      }catch(Exception e){

      if(inputStr!=null "exit".equals(inputStr.trim().toLowerCase())){

      System.out.println("您已成功結束程序");

      input.close();

      System.exit(0);

      }

      if(inputStr!=null "ok".equals(inputStr.trim().toLowerCase())){

      break;

      }

      System.out.println("您輸入的分數(shù)不是數(shù)值類型,");

      System.out.println("若想結束請輸入exit ,若想計算結果請輸入ok");

      count--;

      }

      }

      if(inputScores.size()==0){

      System.out.println("您沒有輸入學生成績,無數(shù)據(jù)可統(tǒng)計,程序結束。");

      return ;

      }

      scores=inputScores.toArray(new Double[inputScores.size()]);

      Arrays.sort(scores);

      min=scores[0];

      max=scores[scores.length-1];

      for(double score :scores){

      total += score;

      }

      avg=total/scores.length;

      System.out.println("總成績是" + total);

      System.out.println("最高分是" + max);

      System.out.println("最低分是" + min);

      System.out.println("平均分是" + avg);

      }

      }

      請問JAVA中如何編程求3個學生的三科成績的平均分?

      平均分和總和都求了

      public class Main {

      public static void main(String[] args) {

      int[] a = new int[] { 60, 70, 80 };

      System.out.println("總分是:" + getSum(a));

      System.out.println("平均分是:" + getAvg(a));

      }

      // 獲得總分

      public static int getSum(int[] a) {

      int sum = 0;

      for (int i = 0; i a.length; i++) {

      sum += a[i];

      }

      return sum;

      }

      // 獲得平均分

      public static int getAvg(int[] a) {

      int sum = 0;

      for (int i = 0; i a.length; i++) {

      sum += a[i];

      }

      return sum / a.length;

      }

      }

      運行結果:

      總分是:210

      平均分是:70

      java編程,三十名同學數(shù)學成績輸入一堆數(shù)組中,求平均分,求總分,求最高分和最低分

      非常推薦用Java8的新特性Stream來解決這類求數(shù)據(jù)統(tǒng)計結果的,真的很方便,代碼簡潔而優(yōu)雅

      用到了IntSummaryStatistics類,這個類就包含了題主說的各種統(tǒng)計結果了

      ListStudent?list?=?Arrays.asList(new?Student(100),?new?Student(59),?new?Student(80),?new?Student(92));

      IntSummaryStatistics?summaryStatistics?=?list.stream().mapToInt(Student::getScore).summaryStatistics();

      System.out.println("最高分:"?+?summaryStatistics.getMax());

      System.out.println("最低分:"?+?summaryStatistics.getMin());

      System.out.println("總分:"?+?summaryStatistics.getSum());

      System.out.println("平均分:"?+?summaryStatistics.getAverage());

      可以參考了解一下


      當前文章:java平均分總分代碼 java均分算法
      本文URL:http://www.ef60e0e.cn/article/doedesg.html
      99热在线精品一区二区三区_国产伦精品一区二区三区女破破_亚洲一区二区三区无码_精品国产欧美日韩另类一区
      1. <ul id="0c1fb"></ul>

        <noscript id="0c1fb"><video id="0c1fb"></video></noscript>
        <noscript id="0c1fb"><listing id="0c1fb"><thead id="0c1fb"></thead></listing></noscript>

        静宁县| 读书| 蓬莱市| 成武县| 潮安县| 瑞昌市| 仁化县| 理塘县| 岗巴县| 延庆县| 临武县| 蒲城县| 合江县| 同德县| 建始县| 鹿泉市| 冕宁县| 博兴县| 肥乡县| 拜泉县| 泰州市| 龙南县| 鄂尔多斯市| 洪泽县| 偏关县| 镶黄旗| 宣恩县| 台北县| 清远市| 西盟| 沂水县| 乐山市| 崇文区| 遵义县| 盖州市| 乌审旗| 依安县| 巴楚县| 定州市| 泰州市| 高阳县|