Two things are wrong:
You start by testing for factor 3, which means you’ll never find 2 factors.
Your loop’s condition –
testFactor > 1– is wrong.
testFactorkeeps growing, so the loop will only terminate when
testFactoroverflows to a negative value. You should terminate when
NumberToFactorbecomes 1. i.e. change the condition to
NumberToFactor > 1.
Oh, and there’s another issue –
Factors seems to be a constructor, but it appears inside a class of a different name –
factorClass. The constructor must have the same name as the class.
CLICK HERE to find out more related problems solutions.