Beginning algorithm that finds the factors of a number, written in Java and is very slow