This allows you to get the length of a string:
Then you can use this little bit trick to test whether a number is odd or even:
return n & 1 == 1;
The rest is just a matter of an
if .. else
block to implement the logic.