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.testFactor
keeps growing, so the loop will only terminate whentestFactor
overflows to a negative value. You should terminate whenNumberToFactor
becomes 1. i.e. change the condition toNumberToFactor > 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.