title: Generate a factor array and print it contents
body: <p>How to create a method that holds an array of integers, then allow that specific method to print all the elements of that array when ever the method is called from a main class?</p>
  
  <p>Here is a program that I did as an example:
  I am trying to find all the possible factors for an <code>int</code> input. I used a method called <code>generateFactors()</code> to store all the possible factors of a number, but I couldn't print the array elements for some reason. In the <code>toString()</code> method, there is an error saying <code>void type not allowed here</code>!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class FactorNumbers {
  
      private int number;
  
      public FactorNumbers(int number) {
          this.number = number;
      }
  
      public int getNumber() {
          return number;
      }
  
      public void setNumber(int number) {
          this.number = number;
      }
  
      public void generateFactors() {
          int[] factors = new int[number];
  
          for (int i = 0; i &lt; number; i++) {
              if ((i + 1 % number) == 0) {
                  factors[i] = i;
                  System.out.println("Factor= " + i);
              } else {
                  factors[i] = 0;
              }
          }
          for (int i = 0; i &lt; number; i++) {
              System.out.println(factors[i] + "");
          }
      }
  
      @Override
      public String toString() {
          return "The factors of " + number + "are: " + generateFactors();
      }
  
  }</code></pre>
  </div>
  </div>
  </p>