java查看平均分代码 平均分的代码

java 计算平均分

import java.math.BigDecimal;

创新互联公司是由多位在大型网络公司、广告设计公司的优秀设计人员和策划人员组成的一个具有丰富经验的团队,其中包括网站策划、网页美工、网站程序员、网页设计师、平面广告设计师、网络营销人员及形象策划。承接:成都网站设计、网站建设、网站改版、网页设计制作、网站建设与维护、网络推广、数据库开发,以高性价比制作企业网站、行业门户平台等全方位的服务。

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

String s = null;

int i = 1; //标识人数

int totalScore = 0; //总分

do

{

System.out.println("请输入第 " + i + " 位学生的成绩(输入 “-1” 结束输入开始计算平均分): ");

s = sc.nextLine();

if (!"-1".equals(s))

{

totalScore = totalScore + Integer.valueOf(s);

i++;

}

}while (!"-1".equals(s));

System.out.println("一共输入了 " + (i-1) + " 位学生的成绩");

System.out.println("总分是:" + totalScore);

System.out.println("平均分是:" + new BigDecimal(totalScore).divide(new BigDecimal(i-1)));

}

}

这个程序可以输入任意数量学生的成绩 然后输出学生的平均分,输入-1结束输入并计算平均分。

急急急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求考试参加的学生的平均分

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("输入考试科数:");

int n = sc.nextInt();

// 存放每科考试的平均分

int []score = new int[n+1];

// 存放每科考试的人数

int []student = new int[n+1];

int sum = 0;

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

System.out.print(i+"号考试参加的人数为:");

student[i] = sc.nextInt();

for(int j=1;j=student[i];j++) {

System.out.print(j+"号学生的成绩为:");

sum+=sc.nextInt();

}

score[i] = sum/student[i];

sum=0;

}

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

System.out.println(k+"号考试参加的人数为"+student[k]+",平均分为:"+score[k]);

}

}

}

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查看平均分代码 平均分的代码
文章分享:http://myzitong.com/article/dooighd.html