public static Integer[] findFactors(int d)
{
List list = new ArrayList();
for(int i = 1; i <= d/2; i++)
{
if(d % i == 0) list.add(new Integer(i));
}
list.add(new Integer(d));
return (Integer[]) list.toArray(new Integer[0]);
}
public static void main(String[] args)
{
Integer[] list = findFactors(20);
for(Integer i : list) System.out.println(i);
}
Output:
1
2
4
5
10
20