Q:

Palindrome program, cannot terminate loop, Project Euler #4

import java.util.ArrayList;
public class Euler4{
    public static void main(String [] args){
                int size = 0;
        int product = 0;

        for(int i = 102; i > 100; i--){
            for(int j = 102; j > 100; j--){
                ArrayList<Integer> digits = new ArrayList<Integer>();
                product = i*j;
                int index = 0;
                while(product > 0){
                    digits.add(index,product%10);
                    product /= 10;
                    index++;
                }
                for(int element : digits)
                    System.out.println("digits :" + element);   
                size = digits.size() - 1;

                if(test(0,size,digits)){
                    System.out.println("i and j " + i + " " + j);
                    break;  
                }
            }
        }
    }

    public static boolean test(int i, int size, ArrayList<Integer> digits){

        if(digits.get(size).equals(digits.get(i))){

            if(size == i || size - i == 1){
                return true;

            }else{
                System.out.println("i: " + i + " size: " + size + " digits@i: " + digits.get(i) +" digits@size " + digits.get(i));
                size--;
                i++;

                if(!test(i, size, digits))  
                    return false;
            }   
        }
        return false;
    }
}

Here's the output:
digits :4 index: 0
digits :0 index: 1
digits :4 index: 2
digits :0 index: 3
digits :1 index: 4
digits :2 index: 0
digits :0 index: 1
digits :3 index: 2
digits :0 index: 3
digits :1 index: 4
digits :2 index: 0
digits :0 index: 1
digits :3 index: 2
digits :0 index: 3
digits :1 index: 4
digits :1 index: 0
digits :0 index: 1
digits :2 index: 2
digits :0 index: 3
digits :1 index: 4
i: 0 size: 4 digits@i: 1 digits@size 1
i: 1 size: 3 digits@i: 0 digits@size 0

I think there's a problem with the while loop and a problem with the recursion. The values that get ran through the test() method is the last set of values that goes into the array and that is 10201 so then even though the while loop messed up, the recursive method should still have returned true. I don't know why it's not. 
This is the problem: 
http://projecteuler.net/problem=4
Thanks. 
EDIT: I fixed it up to be a bit more efficient and to give the max palindrome instead of just listing palindromes. Here's the final if anyone is interested: http://pastebin.com/qJUpZVzK

A:

Your third call to test is returning true, but your second call to test is not using that value.  It's falling to the bottom of the method and returning false, when you actually want it to return true.
When you call test recursively, you want to return true (from test) if the recursive call returned true.
Change
if(!test(i, size, digits))  
      return false;

near the bottom, to
return test(i, size, digits);

