//【程序50】TestStu.java 题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),
//计算 出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件"stud"中。
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class TestStuApp {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请依次输入学生号,姓名,三门课成绩,用逗号隔开,每个学生之间用句号隔开");
String str = input.next();
String[] student = str.split("\\.");
for(int i=0;i<student.length;i++){
System.out.print(student[i]+" ");
}
BufferedWriter bw = new BufferedWriter(new FileWriter("F:\\stud.txt"));
for (int i = 0; i < student.length; i++) {
String[] scores = student[i].split("\\,");
bw.write(student[i]);
int[] num1 = new int[3];
int sum = 0;
for (int m = 0; m < 3; m++) {
num1[m] = Integer.parseInt(scores[m + 2]);
sum += num1[m];
}
bw.write(".平均分:" + sum/3);
System.out.println(sum/3);
}
bw.flush();
bw.close();
}
}
来自Joseph-Howard的博客(http://blog.csdn.net/huolei_blog/article/details/23510105)