Java 练习:字符串反转
package com.swift; public class String_Reverse_Test { public static void main(String[] args) { /* * 字符串反转 */ String str="abcdefghijklmn"; System.out.println(str); char[] c_qian=str.toCharArray(); char[] c_hou=new char[c_qian.length]; for(int i=0;i<c_qian.length;i++) { c_hou[c_qian.length-1-i]=c_qian[i]; } String str_fan=String.valueOf(c_hou); System.out.println(str_fan); } }
也可以放到StringBuffer中用reverse方法
Never waste time any more, Never old man be a yong man