⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 computemeandeviation.java

📁 此源码为机械工业出版社出版的《Java语言程序设计》第三版所配套的书中所有源代码。
💻 JAVA
字号:
// ComputeMeanDeviation.java: Demonstrate using the math methods
public class ComputeMeanDeviation
{
  // Main method
  public static void main(String[] args)
  {
    int number = 0; // Store a random number
    double sum = 0; // Store the sum of the numbers
    double squareSum = 0; // Store the sum of the squares

    // Create 10 numbers, find its sum, and its square sum
    for (int i=1; i<=10; i++)
    {
      // Generate a new random number
      number = (int)Math.round(Math.random()*1000);
      System.out.println(number);

      // Add the number to sum
      sum += number;

      // Add the square of the number to squareSum
      squareSum += Math.pow(number, 2); // Same as number*number;
    }

    // Find mean
    double mean = sum/10;

    // Find standard deviation
    double deviation = Math.sqrt((squareSum - mean)/(10 - 1));

    // Display result
    System.out.println("The mean is " + mean);
    System.out.println("The standard deviation is " + deviation);
  }
}

⌨️ 快捷键说明

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