2
I’m trying to solve the following exercise:
A string collection S is recursively defined 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 tell which of the following strings belong to S:
(a) to
(b) ab
(c) tab
(d) aaab
(e) bbbbb
My code is as follows:
static boolean funcao(String str){
if(str.equals("a") || str.equals("b"))
return true;
return(...)
At last return
is where I can’t solve, I know in theory he should be more or less like this:
retorna(str[ultimo caracter] == 'b' && funcao(str[do primeiro ao penúltimo caractere]);
But I’m not getting it, someone would know to help me?