zoukankan      html  css  js  c++  java
  • 有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,原有的数据和计算出的平均分数存放在磁盘文件 "stud "中.

    有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,原有的数据和计算出的平均分数存放在磁盘文件 "stud "中.

    package com.mumu.ready;

    import static com.mumu.ready.Print.*;

    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.util.Scanner;

    public class Stud {

    public static void main(String[] args) throws IOException {
    FileOutputStream out = new FileOutputStream(new File("D:\stud.txt"),true);
    out.write(("学号: 姓名: 数学: 语文: 英语: 平均分: ").getBytes());
    for (int i = 0; i < 5; i++) {
    print("请输入学生的学号,姓名,数学成绩,语文成绩,英语成绩:");
    Scanner can = new Scanner(System.in);
    int no = can.nextInt();
    out.write((no + " ").getBytes());
    String name = can.next();
    out.write((name + " ").getBytes());
    float[] num = new float[3];
    for (int k = 0; k < 3; k++) {
    num[k] = can.nextFloat();
    out.write((num[k] + " ").getBytes());
    }
    float avg = (num[0] + num[1] + num[2]) / 3;
    out.write((avg + " ").getBytes());
    }
    out.flush();

    out.close();
    }
    }

  • 相关阅读:
    (一〇八)iPad开发之横竖屏适配
    ZOJ 1414:Number Steps
    HDU 1391:Number Steps
    ZOJ 1871:Steps
    POJ 2590:Steps
    POJ 2629:Common permutation
    POJ 2562:Primary Arithmetic
    POJ 2505:A multiplication game
    HDU 1517:A Multiplication Game
    POJ 3650:The Seven Percent Solution
  • 原文地址:https://www.cnblogs.com/liumumu2014/p/3803906.html
Copyright © 2011-2022 走看看