title: how to factor a number java
body: <p>I need to factorize a number like 24 to 1,2,2,2,3. My method for that:</p>
  
  <pre><code>static int[] factorsOf (int val) {
            int index = 0;
        int []numArray = new int[index];
  
        System.out.println("\nThe factors of " + val + " are:");
        for(int i=1; i &lt;= val/2; i++)
        {
            if(val % i == 0)
            {   
                numArray1 [index] = i;
                index++;
            }
        }
  
        return numArray;
  
    }
  </code></pre>
  
  <p>however, it is not working. Can anyone help me for that?</p>