You are incrementing ‘n’ when the number is prime and palindrome, but the question asks you to stop there. Your code doesn’t work for the given test case also. It gives 31 as output while the output should be 101.
Instead of ‘and’ use ‘or’ operator. ‘&&’ doesn’t work because the loop will terminate when you encounter either a prime number or a palindrome and it need not encounter both. http://en.wikipedia.org/wiki/Logical_conjunction .
Check how ‘and’ and ‘or’ operator works. I think you may understand why it is not working after reading that. If you still don’t get, you can ask again.