字符串倒叙输出,StringBuffer,String

来源:互联网 发布:注册六西格玛黑带 知乎 编辑:程序博客网 时间:2024/05/17 18:01
package test;import java.util.Scanner;public class LianXi {    public static void main(String[] args) {        String s;        System.out.println("input");        s = new Scanner(System.in).nextLine();        StringBuffer sb = new StringBuffer(s);        System.out.println(sb.reverse().toString());//        LianXi.otherMethod();    }    public static void otherMethod() {        String s = "";        System.out.println("input:");        s = new Scanner(System.in).nextLine();        char[] c = s.toCharArray();        for (int i = c.length - 1; i >= 0; i--) {            System.out.print(c[i]);        }    }}/*StringBufferStringBuffer(String str)Constructs a string buffer initialized to the contents of the specified string.StringBuffer    reverse()Causes this character sequence to be replaced by the reverse of the sequence.Stringchar[]  toCharArray()Converts this string to a new character array. */
原创粉丝点击