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

📄 debug11_5.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package questions.c11;
public class Debug11_5 extends Thread {
   private int samples;
   private double average;
   public Debug11_5( int s ) {
      samples = s;
   }
   public synchronized void run() {
      java.util.Random r = new java.util.Random();
      double sum = 0.0;
      for( int i=0; i < samples; i++ ) {
         sum += r.nextDouble();
      }
      average = sum/samples;
   }
   public double getAverage() {
      while ( average == 0.0 ) try {
	 wait();
      } catch ( InterruptedException ix ) {
	 System.out.println( ix );
      }
      return average;
   }
   public static void main( String[] args ) {
      Debug11_5 x = new Debug11_5( 500000 );
      x.start();
      System.out.println( "Average = "
			  + x.getAverage() );
   }
}

⌨️ 快捷键说明

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