title: Loss of precision using arrays and long data types
body: <p>This is a program designed to estimate the value of pi using Buffons needle simulation. The problem I am having here is that if the user inputs a really big number, the program crashes. I'm assuming it's because I am not using a long data type instead of the int. When I tried to change the number of trials in the trials method to a long data type, it kept giving me an error saying that there was a lack of precision for the length of the array. I can't figure out how to fix this problem.. Help?</p>
  
  <pre><code>import java.util.Scanner;
  public class Darts
  {
      public static long trials() //User Inputs number of trials
      {
          long input;
          Scanner in = new Scanner(System.in);
  
          System.out.print("How many darts/trials? ");
          input = in.nextLong();
  
          return input;
      }
  
      public static double [] randomX(long trial) // Randomly generates numbers for the x coordinate on the amounts of trials
  
      {
          double [] randNumArrayX = new double[trial];
          for(int i = 0; i &lt; trial; i++)
          {
              randNumArrayX[i] = Math.random();
          }
          return randNumArrayX;
      }
  
      public static double [] randomY(long trial) // Randomly generates numbers forthe y coordinate on the amounts of trials
      {
          double [] randNumArrayY = new double[trial];
          for(int i = 0; i &lt; trial; i++)
          {
              randNumArrayY[i] = Math.random();
          }
          return randNumArrayY;
      }
  
      public static int [] dartBoard(double [] randx, double [] randy) // determines whether the dark hit the board or not
      {
          int [] hitMiss = new int[randx.length];
          int [] trials = new int[randx.length];
  
          for(int i = 0; i &lt; randx.length; i++)
          {
              if( Math.pow(randx[i] , 2) + Math.pow(randy[i] , 2) &lt;= 1)
              {
                  hitMiss[i] = 1;
              }
              else
              {
                  hitMiss[i] = 0;
              }
          }
          return hitMiss;
      }
  
      public static double [] calcPi(int [] h) // Calculates pi using randomly generated numbers
      {
          int hitCounter = 0;
          double [] pi = new double[h.length];
  
          for(int i = 0; i &lt; h.length; i++)
          {
              if(h[i] == 1)
              {
                  hitCounter++;
              }
              pi[i] = 4*(hitCounter/(i + 1));
          }
          return pi;
      }
  
      public static void print(double [] pi) // prints results
      {
          for(int i = 0; i &lt; 10; i++)
          {
              System.out.printf("%-7s%2d%-8s%-10.6f%n", "Trial [", i, "]: pi = ", pi[i]);
          }
          System.out.println("\t   .....");
          System.out.printf("%-17s%-10.6f%n", "Estimate of pi = ", pi[pi.length -1]);
      }
  
      public static void main(String [] args) // main method
      {
          long t = trials();
          double [] x = new double[t];
          double [] y = new double[t];
          int [] h = new int[t];
          double [] p = new double[t];
          x = randomX(t);
          y = randomY(t);
          h = dartBoard( x , y );
          p = calcPi( h );
          print(p);
      }
  }
  </code></pre>