Advertisement
KuoHsiangYu

NetBeans_Eclipse_測試程式印出字元速度

Sep 30th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class MainClass {
  4.  
  5.     public static void main(String[] args) {
  6.         Random r = new Random();
  7.         long t1 = System.nanoTime();
  8.         for (int i = 0; i < 1000; i++) {
  9.             for (int j = 0; j < 1000; j++) {
  10.                 if (r.nextInt(4) == 0) {
  11.                     System.out.printf("O");
  12.                 } else {
  13.                     //System.out.printf("#");
  14.                     System.out.printf("B");
  15.                     //System.out.printf("中");
  16.                 }
  17.             }
  18.             System.out.printf("\n");
  19.         }
  20.         long t2 = System.nanoTime();
  21.         double seconds = (double) (t2 - t1) / 1000000000.0;
  22.         System.out.printf("%f seconds\n", seconds);
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement