close

 

package p01;

import java.util.Scanner;

public class MaxMin {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int score;
        int cound = 0;//次數
        float avg = 0;//平均
        int total = 0;//總分
        int max = 0;
        int min = 100;
        while (true) {
            System.out.println("現在最高分= " + max);
            System.out.println("現在最低分= " + min);
            System.out.println("-----------------");
            System.out.print("輸入成績(-1結束)");
            score = sc.nextInt();

            if (score == -1) {
                break;
            }
            if (score > 100 || score < 0) {
                System.out.println("錯誤的成績");
                continue;
            }
            cound++;
            total += score;
            avg = (float) total / cound;
            if (score > max) {
                max = score;
            }
            if (score < min) {
                min = score;
            }

        }
        System.out.println("Max= " + max);
        System.out.println("Min= " + min);
        System.out.println("Total= " + total);
        System.out.println("Average = " + avg);
        System.out.println("總共" + cound + "個成績");

    }

}

arrow
arrow
    文章標籤
    程式語言 HomeWork
    全站熱搜

    蛋餅Brook 發表在 痞客邦 留言(0) 人氣()