dive.java

来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 46 行

JAVA
46
字号
import java.io.*;

class Dive {

    /* The Dive Class    by J M Bishop Dec 1996
     *                    Java 1.1 October 1997
     * Stores and assesses diving scores for one dive.
     *
     * Illustrates arrays
     */

    int minJudge, maxJudge, minScore, maxScore, sum;

    private int noOfJudges;
    private int score [];

    Dive (int n) {
      noOfJudges = n;
      score = new int [noOfJudges];
    }

    void setScore (int i, int s) {
      score [i] = s;
    }

    void assessScores() {
        minScore = 10;
        maxScore = 0;
        sum = 0;
        for (int i = 0; i < noOfJudges; i++) {
            sum += score[i];
            if (score[i] <= minScore) {
                minScore = score[i];
                minJudge = i;
            }
            if (score[i] > maxScore) {
                maxScore = score[i];
                maxJudge = i;
            }
        }
        minJudge++;
        maxJudge++;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?