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

[368 byte] By [riponc007a] at [2007-9-29 0:34:57]
# 1
And do you have a question?
BarneyGumblea at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 2
The terminating null character? What language are we talking about here?
levi_ha at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 3
Sounds like a question from an out-of-touch prof conforming his course to Java.
rkippena at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 4
Hey levi h,We are talking about Java here.
riponc007a at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 5
well you're not going to be finding terminating nulls on the end of your java strings; thats for sure.
silkma at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 6

> 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...

MooMana at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 7
> well you're not going to be finding terminating nulls> on the end of your java strings; thats for sure.He could if he defined his own string class.
TerryMoorea at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 8

> 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.

MrSillya at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...
# 9
[code]private String reverseThis(String arg){int total=ch.length;i++;newString += ch[total - i]; if(i != total) reverseThis(arg);return newString;}[code]
Sscottiesa at 2007-7-13 3:02:39 > top of Java-index,Other Topics,Algorithms...