I'm trying to solve the following exercise:
An S collection of strings is defined recursively by:
- 'a' and 'b' belong to S;
- If X belongs to S, then Xb also belongs to S;
Write a procedure that implements this definition recursively and say which of the following strings belong to S:
(a) to
(b) ab
(c) flap
(d) aaab
(e) bbbbb
My code looks like this:
static boolean funcao(String str){
if(str.equals("a") || str.equals("b"))
return true;
return(...)
In the last return
is where I can not solve, I know that in theory it should be something like this:
retorna(str[ultimo caracter] == 'b' && funcao(str[do primeiro ao penúltimo caractere]);
But I can not, could anyone help me?