使用 String charAt 方法

package net.javaguides.corejava.string;
/**
* 
* @author Ramesh Fadatare
*
*/
public class ReverseWithStringChatAt{
public static void main(String[] args) {
ReverseWithStringChatAt reverseWithStringBuilder = new ReverseWithStringChatAt();
reverseWithStringBuilder.reverseWithStringBuilder("javaguides");
}
public String reverseWithStringChatAt(String string) {
final StringBuilder builder = new StringBuilder();
for (int i = (string.length() - 1); i >= 0; i--) {
builder.append(string.charAt(i));
}
display(string, builder.toString());
return builder.toString();
}
private void display(String input, String output) {
System.out.println(" input string :: " + input);
System.out.println(" output string :: " + output);
}
}
登录后复制

输出:

input string :: javaguides
output string :: sediugavaj
登录后复制

以上就是java如何使用String charAt方法反转字符的详细内容,更多请关注Work网其它相关文章!

08-26 18:22