java问题,求助……

来源:百度知道 编辑:UC知道 时间:2024/05/09 12:42:50
/*声明一个数组,保存一个学生的数学、语文、英语、物理、化学、信息技术6门
课程的成绩,成绩值可以精确到0.1分。打印输出该学生总成绩、平均成绩。*/

import java.io.*;
public class x4_3 {
public static void main(String args[])throws IOException{
int i,count=6;
float Math[]=new float[count];float Chin[]=new float[count];
float Eng[]=new float[count];float Phy[]=new float[count];
float Chem[]=new float[count];float Info[] =new float[count];
float sum=0.0f,aver=0.0f;
String strMath,strChin,strEng,strPhy,strChem,strInfo;
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入该生的成绩!");
for(i=0;i<count;i++)
{
switch(i){
case 0: {System.out.print("数学:");
strMath=buf.readLine();
Math[count]=Float.parseFloat(strMath);
}break;

import java.io.*;
import java.text.DecimalFormat;

public class x4_3 {
public static void main(String args[]) throws IOException {
int i, count = 6;
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
float[] score = new float[count];
String[] sub = {"数学","语文","英文","物理","化学","信息技术"};
System.out.println("请依次输入各科成绩:");
float sum = 0;
for (i = 0; i < 6; i++) {
System.out.println("请输入" + sub[i] + " 成绩:");
score[i] = Float.parseFloat(buf.readLine());
sum += score[i];
}

float avg = sum / 6;
System.out.println("总成绩:" + sum);
System.out.println("平均成绩:" + new DecimalFormat("#.0").format(avg));

}
}