package net.megaroid.math;

import java.util.Scanner;

public class Factors {
	
	private int mNumber;
	private int[] mFactors; 
	private int mCount;
	
	public Factors(int number) {
		mNumber = number;
	}

	public int getNumber() {
		return mNumber;
	}
	
	public void printAllFactors() {
		if (mFactors == null) {
			initialize();
		}
		
		System.out.print("Factors: ");
		for (int i = 0; i < mCount; i++) {
			System.out.print(mFactors[i] + " ");;
		}
		System.out.println("");
 	}
	
	private void initialize()
	{
		int sqrtN = (int)Math.sqrt(mNumber);
		mCount = 0;
		
		mFactors = new int[sqrtN * 2];
		
		for (int i = 1; i <= sqrtN; i++) {
			if (mNumber % i == 0) {
				mFactors[mCount++] = i;
				if (i * i != mNumber) {
					mFactors[mCount++] = mNumber / i;
				}
			}
		}
	}
	
	public static void main(String[] args) {
		
		System.out.print("Input a number : ");

		Scanner scanner = new Scanner(System.in);
		int num = scanner.nextInt();
		scanner.close();
		
		Factors f = new Factors(num);
		System.out.println("The number is " + f.getNumber());
		
		f.printAllFactors();
	}
}

@@ -46,16 +46,45 @@
 Scanner;
+%0Aimport java.util.LinkedList;
 %0A%0Apublic
@@ -137,44 +137,36 @@
 ate 
+L
 in
-t%5B%5D mFactors; %0A%09private int mCount
+kedList%3CInteger%3E mFactors
 ;%0A%09%0A
@@ -401,28 +401,18 @@
 t i 
-= 0; i %3C mCount; i++
+: mFactors
 ) %7B%0A
@@ -435,27 +435,17 @@
 int(
-mFactors%5Bi%5D
+i
  + %22 %22);
 ;%0A%09%09
@@ -440,17 +440,16 @@
  + %22 %22);
-;
 %0A%09%09%7D%0A%09%09S
@@ -550,22 +550,8 @@
 r);%0A
-%09%09mCount = 0;%0A
 %09%09%0A%09
@@ -570,22 +570,29 @@
 new 
+L
 in
-t%5BsqrtN * 2%5D
+kedList%3CInteger%3E()
 ;%0A%09%09
@@ -672,22 +672,15 @@
 tors
-%5BmCount++%5D = i
+.add(i)
 ;%0A%09%09
@@ -722,21 +722,13 @@
 tors
-%5BmCount++%5D = 
+.add(
 mNum
@@ -734,16 +734,17 @@
 mber / i
+)
 ;%0A%09%09%09%09%7D%0A

Use LinkedList instead of Array