title: Sum all the values in an array of factorials and print the result
body: <p>I want to write a java program which will calculate the first 20 factorial and store them in an array. Then go through the array and sum all of the items and print the result on the screen. </p>
  
  <p>Here is my code but I think I did something wrong:</p>
  
  <pre><code>public class ArrayQuestion4 {
  
      public static void main(String[] args) {
          long array[]= new long[20];
          long temp=1;
  
          for ( int i=1; i&lt;20; i++){
              temp = i*(i+1);
              temp = temp*(temp+1);
              array[i]=temp;
              System.out.println(array[i]);
          }
  
          for ( int i=1; i&lt;20; i++){
              temp = array[i];
              temp = array[i]+(array[i+1]);
              temp = temp+(temp+1);
              System.out.println(temp);
          }       
      }
  }
  </code></pre>
  
  <p>The answer that comes out is not correct by the way.</p>
  
  <p>I figure it out the correct code is this:</p>
  
  <pre><code>public class ArrayQuestion4 {
  
  public static void main(String[] args) {
      long array[]= new long[20];
      array[0]=1;
      long temp=0;
      for ( int i=1; i&lt;20; i++){
          array[i]=array[i-1]*(i+1);
          System.out.println(array[i-1]+"*"+(i+1)+" = "+array[i]);
      }   
  
      for ( int i=1; i&lt;20; i++){
         temp = temp + array[i-1] + array[i];
      }   
      System.out.println(" ");
      System.out.println("Sum = "+temp);
  }
  }
  </code></pre>