欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java平均分總分代碼 java均分算法

JAVA代碼問題!輸入5名學(xué)生的成績(jī),并計(jì)算總成績(jī),平均分,最高分,最低分

public static void main(String[] args) {

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

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("請(qǐng)輸入5名學(xué)生的成績(jī):");

Scanner input = new Scanner(System.in);

while(count5){

try{

if(count 5){

System.out.println("請(qǐng)輸入第"+(count+1)+"個(gè)分?jǐn)?shù):");

}

inputStr=input.nextLine();

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

}catch(Exception e){

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

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

System.exit(0);

}

System.out.println("若想結(jié)束請(qǐng)輸入:exit");

System.out.print("您輸入的分?jǐn)?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("總成績(jī)是" + 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("請(qǐng)輸入要統(tǒng)計(jì)學(xué)生的成績(jī)(理論上可以輸入無(wú)限個(gè),前提是你有那么大的內(nèi)存):");

while(true){

try{

System.out.println("請(qǐng)輸入第"+count+++"個(gè)分?jǐn)?shù),或輸入ok進(jìn)行計(jì)算,離開請(qǐng)輸入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("您已成功結(jié)束程序");

input.close();

System.exit(0);

}

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

break;

}

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

System.out.println("若想結(jié)束請(qǐng)輸入exit ,若想計(jì)算結(jié)果請(qǐng)輸入ok");

count--;

}

}

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

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

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("總成績(jī)是" + total);

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

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

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

}

}

請(qǐng)問JAVA中如何編程求3個(gè)學(xué)生的三科成績(jī)的平均分?

平均分和總和都求了

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;

}

}

運(yùn)行結(jié)果:

總分是:210

平均分是:70

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

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

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

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());

可以參考了解一下

新聞標(biāo)題:java平均分總分代碼 java均分算法
本文鏈接:http://chinadenli.net/article36/doedesg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作搜索引擎優(yōu)化微信公眾號(hào)服務(wù)器托管品牌網(wǎng)站制作App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司