I've managed to solve the problem and fix the code (below) but for numbers larger than 400 it becomes very very slow. Any suggestions on how this could be enhanced for larger numbers?
public class TriangleFinder implements Runnable {
public long target; // number to divisors
public long outputValue;
public boolean finished = false;
private Thread runner;
TriangleFinder(long inTarget) {
target = inTarget;
if (runner == null) {
runner = new Thread(this);
runner.start();
}
}
public void run() {
for (long i = 0; getDivisors(getTriangle(i)) < target; i++) {
outputValue = getTriangle(i + 1);
}
finished = true;
}
public long getTriangle(long checkNum) {
long triangleValue = 0;
for (long i = checkNum; i > 0; i--) {
triangleValue += i;
}
return triangleValue;
}
public long getDivisors(long checkTri) {
long divisorCount = 0;
for (long i = 1; i <= checkTri; i++) {
if (checkTri % i == 0) {
divisorCount++;
}
}
return divisorCount;
}
}