首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java兑现字符串反转

2013-03-21 
Java实现字符串反转public class StrRev {//operator methodpublic static void strPrint(String string){

Java实现字符串反转

public class StrRev {//operator methodpublic static void strPrint(String string){System.out.print(string);}public static void strPrint(char ch){System.out.print(ch);}//method 1public static void strRev(String str){for(int i = str.length() - 1;i >= 0;i --){strPrint(str.charAt(i));}}//method 2public static void strRev1(String str){StringBuffer sb = new StringBuffer(str);String newstr = sb.reverse().toString();strPrint(newstr);}/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubstrRev("abcdd");strRev1("abcdd");}}

热点排行