java在不使用任何内置方法的情况下反转字符串
Possible Duplicate:
Printing reverse of any String without using any predefined function?
请建议如何在不使用内置方法的情况下反转字符串。我只想使用字符串类,请建议假设有一个字符串“john is a boy”并打印“yob a si nhoj”
你可以在下面搜索框中键入要查询的问题!
Possible Duplicate:
Printing reverse of any String without using any predefined function?
请建议如何在不使用内置方法的情况下反转字符串。我只想使用字符串类,请建议假设有一个字符串“john is a boy”并打印“yob a si nhoj”
# 1 楼答案
此方法将向后返回字符串。你所要做的就是向后遍历字符串,并将其添加到另一个字符串中
可以使用for循环执行此操作,但首先检查字符串的长度是否大于0
Java字符串有一个方法“charAt(index)”,它在字符串的位置返回一个字符,其中位置0是第一个字符。所以,如果你想反转“Boy”,你可以从字母2开始,然后是1,然后是0,然后把它们一起添加到一个新的字符串中,得到“yoB”