程序50
来源:互联网 发布:vmware12安装centos几 编辑:程序博客网 时间:2024/05/01 08:07
/*题目:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件"stud"中。*/
import java.util.*;import java.io.*;public class Example50{public static void main(String args[]) throws IOException{Scanner sc=new Scanner(System.in);System.out.print("请输入第一个学生的学号、姓名和三门课成绩:");String str1=sc.next();String[] arr1=str1.split("\\,");System.out.print("请输入第二个学生的学号、姓名和三门课成绩:");String str2=sc.next();String[] arr2=str2.split("\\,");System.out.print("请输入第三个学生的学号、姓名和三门课成绩:");String str3=sc.next();String[] arr3=str3.split("\\,");//第一个学生平均分计算int sum1=0;for(int i=2;i<arr1.length;i++){sum1=sum1+Integer.parseInt(arr1[i]);}double avg1=(double)sum1/3;//第二个学生平均分计算int sum2=0;for(int i=2;i<arr2.length;i++){sum2=sum2+Integer.parseInt(arr2[i]);}double avg2=(double)sum2/3;//第三个学生平均分计算int sum3=0;for(int i=2;i<arr3.length;i++){sum3=sum3+Integer.parseInt(arr3[i]);}double avg3=(double)sum3/3;//写入到文件中BufferedWriter bw = new BufferedWriter(new FileWriter("h:\\stud.txt")); bw.write(str1);bw.write(" 平均分:" + avg1);bw.write("\r\n");bw.write(str2);bw.write(" 平均分:" + avg2);bw.write("\r\n");bw.write(str3);bw.write(" 平均分:" + avg3);bw.flush();//清空缓存bw.close();//输出流关闭}}
阅读全文
0 0
- 程序50
- 程序
- 程序
- 程序
- 程序!~~`````
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 程序
- 在线编译mbed开发环境应用记录(2)
- 关于算法复杂度
- 程序49
- Python笔记--装饰器重载
- hdu3472 HS BDC (混合图的欧拉链路)
- 程序50
- 十分钟学会win10系统封装之系列教程(一):在VMware Workstation虚拟机上安装win10母盘系统
- Linux下安装Nginx
- RPGMaker MV 插件基础06:了解游戏数据与F8调试
- win10下安装Docker
- Android Input流程分析(三):InputReader
- HashMap深度解析(一)
- 多态的四种形式
- java面试-hashmap总结