Advertisement
Guest User

Untitled

a guest
May 29th, 2015
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class sum
  4. {
  5.   static class X
  6.   {
  7.     double i, j, k;
  8.   }
  9.  
  10.   private static final int SIZE = 1 << 24;
  11.   static ArrayList<X> ax;
  12.  
  13.   public static void main( String args[] )
  14.   {
  15.     System.out.println( "press return to allocate ArrayList<X>" );
  16.     System.console().readLine();
  17.  
  18.     ax = new ArrayList<X>( SIZE );
  19.    
  20.     for( int i = 0; i < SIZE; i ++ )
  21.     {
  22.       X x = new X();
  23.  
  24.       x.i = Math.random();
  25.       x.j = Math.random();
  26.       x.k = Math.random();
  27.       ax.add( x );
  28.     }
  29.    
  30.     System.out.println( "press return to make sum" );
  31.     System.console().readLine();
  32.    
  33.     double result = 0.0;
  34.     double t = System.nanoTime();
  35.    
  36.     for( int m = 2; m < 100; m++ )
  37.       for( int i = 0; i < SIZE; i++ )
  38.       {
  39.     X x = ax.get( i );
  40.    
  41.     result += x.i * m;
  42.     result += x.j * m;
  43.     result += x.k * m;
  44.       }
  45.  
  46.     t = System.nanoTime() - t;
  47.     System.out.println( result );
  48.     System.out.println( t / 1000000000.0 );
  49.   }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement