calctemp.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 31 行

JAVA
31
字号
import java.io.*;
import java.math.*;

public class CalcTemp
{

    public static void main (String args[]) throws IOException
    {
        BufferedReader consoleInput = new BufferedReader(new InputStreamReader(System.in));
        int[] recentYear = new int[20];
        int sum=0, i;
        for (i=0; i<recentYear.length; i++)
        {
            System.out.print("Enter value: ");
            recentYear[i] = Integer.parseInt(consoleInput.readLine());
            sum = sum + recentYear[i];
        }
        int recentMean = sum / recentYear.length;
        System.out.println("Average is: " + recentMean);
        int[] category = new int[21];
        int spot;
        for (i=0; i<recentYear.length; i++)
        {
            // the full decimal 5.0 is needed to force it to do float division
            spot = (int) Math.floor((recentYear[i] - recentMean + 2) / 5.0) + 10;
            System.out.println("Spot is :" + spot);
            category[spot]++;
        }
    }
}

⌨️ 快捷键说明

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