135-1821-9792

java总分代码怎么打 java中分数怎么打

java编程,三十名同学数学成绩输入一堆数组中,求平均分,求总分,求最高分和最低分

非常推荐用Java8的新特性Stream来解决这类求数据统计结果的,真的很方便,代码简洁而优雅

创新互联专业为企业提供镇坪网站建设、镇坪做网站、镇坪网站设计、镇坪网站制作等企业网站建设、网页设计与制作、镇坪企业网站模板建站服务,10余年镇坪做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

用到了IntSummaryStatistics类,这个类就包含了题主说的各种统计结果了

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成绩总成绩和平均分的代码?

//

import java.util.Scanner;

//

public class Test2014 {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.println("输入学生人数:");

int n = sc.nextInt();

int sum = 0;

for(int i = 1;i = n;++i){

System.out.println("输入第"+i+"个学生成绩:");

sum += sc.nextInt();

}

System.out.println("总成绩是:"+sum+" "+"平均成绩是:"+(double)sum/n);

}

}

JAVA代码问题!输入5名学生的成绩,并计算总成绩,平均分,最高分,最低分

public static void main(String[] args) {

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)+"个分数:");

}

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("您输入的分数不是数值类型,");

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("请输入要统计学生的成绩(理论上可以输入无限个,前提是你有那么大的内存):");

while(true){

try{

System.out.println("请输入第"+count+++"个分数,或输入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("您输入的分数不是数值类型,");

System.out.println("若想结束请输入exit ,若想计算结果请输入ok");

count--;

}

}

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

System.out.println("您没有输入学生成绩,无数据可统计,程序结束。");

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总分代码怎么打 java中分数怎么打
文章源于:http://kswsj.com/article/hjgjsc.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号