当前位置 : 主页 > 编程语言 > c++ >

String 字符串反转

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt public class StringReverse { private String string = "zhangshuai"; @Test public void test(){ System.out.println(reverse1()); System.out.println(reverse2()); System.out.println(reverse3(string)); } /** * 利用数组反转 * @r
gistfile1.txt
public class StringReverse {

    private String string = "zhangshuai";

    @Test
    public void test(){
        System.out.println(reverse1());
        System.out.println(reverse2());
        System.out.println(reverse3(string));
    }

    /**
     * 利用数组反转
     * @return string
     */
    public String reverse1(){
        char[] chars = string.toCharArray();
        //不是实际长度而是其-1
        int length = chars.length;
        for(int i=0;i
网友评论