andy colins wrote:the problem as follows:
you have a boolean method called "check" . the input for this method is String.
the method checks if the string got pairs of '*' or '+' or '-' . if it does, the answer is true.
but if the '+' or '-' located next to another '+', '-' ,(like '++' or '--' , the answer is false.
Welcome to the Ranch!
I'm not quite sure what constitutes a pass or a fail in your check method though. What do you mean by pairs of '*' etc? Do you mean a String that has exactly two instances of those characters? Does it matter where those instances are? Do they have to be at the beginning and end of the String, or can they be anywhere?
You say they fail the check if the characters appear next to each other. Does that mean they fail the check if they appear next to each other anywhere in the String, or if the String only has 2 characters?
Perhaps you could give some examples of what Strings pass and what Strings fail the check.
andy colins wrote:. i have tried to think a lot about it, but so far, nothing came to mind about the solution
Well the Ranch won't give you the solution (which I'm sure isn't what you're after anyway) so you'll have to show us what you have so we can help.
In the meantime
you should think about the following things. Recursion is the technique of having a method that calls itself repeatedly to solve a problem. Each time it calls itself again it makes the problem a little simpler. At some point the recursion needs to terminate (otherwise it will go on forever), so before the method calls itself again it needs to check if it can work out the answer yet.
So, a recursive method will look something like the following pseudo-code...
In this case, making the problem simpler probably means making the String a little shorter each time your method calls itself.
If your String runs out of characters then that is one solution, and you would return false.
If you find the situation you are looking for then that is the other solution, and you return true.
However until I understand exactly what Strings will pass and fail your check I can't guide you to a more specific implementation.