the question is simple:
Line up every number from 1 to 1000 who are not divisions of 3 or 5 and multiply them together. e.g 1 - 10 would be "1 * 2 * 4 * 7 * 8" = 448
My code looks like this:
ArrayList<Integer> list = new ArrayList();
for(int i = 1; i <= 1000; i++)
{
list.add(i);
}
for(int k = 0; k < list.size(); k++)
{
if(list.get(k) % 3 == 0 || list.get(k) % 5 == 0)
{
list.remove(k);
}
}
int answer = 1;
for(int x = 0; x < list.size(); x++)
{
answer *= list.get(x);
}
System.out.println(answer);
The first two for/loops works well but at the third something clearly goes wrong as answer keeps getting returned at a 0 value, which doesn't make sense since answer is not 0 and no value in list is 0.
Any thoughts?