Print a string backwards by recursive function
Hello all,
Please solve the following problem by using Java.
Problem: Write a recursive method stringReverse that takes a character array containing a string as an argument, prints the string backwards and returns nothing. The method should stop processing and return when the terminating null character is encountered.
Thanking u,
Ripon
> Hello all,
> Please solve the following problem by using Java.
>
> Problem: Write a recursive method stringReverse that
> takes a character array containing a string as an
> argument, prints the string backwards and returns
> nothing. The method should stop processing and return
> when the terminating null character is encountered.
>
> Thanking u,
> Ripon
And are you expecting that someone will just give you the code? Or were you just typing in this post for practice? Are you stuck and need help? You need to give us something more to go by...
> Hello all,
> Please solve the following problem by using Java.
>
> Problem: Write a recursive method stringReverse that
> takes a character array containing a string as an
> argument, prints the string backwards and returns
> nothing. The method should stop processing and return
> when the terminating null character is encountered.
>
> Thanking u,
> Ripon
OK, I'm feeling generous today.
public void stringReverse(String s) {
stringReverse(s.substring(1));
System.out.print(s.substring(0, 1));
}
That does it for string objects. Now you just have to adapt it to character arrays.