A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 半世心修 中级黑马   /  2015-5-29 09:21  /  736 人查看  /  8 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

又一个小算法:
  1. public class Test {
  2.         public static void main(String args[]){
  3.                 test("this is a test");
  4.         }
  5.         public static void test(String str){
  6.                 if(str!=null){
  7.                         String newStr = "";
  8.                         for(int i=0;i<str.length();i++)
  9.                         {
  10.                                 char c = str.charAt(str.length()-1-i);
  11.                                 System.out.println(str.length()-1-i);
  12.                                 newStr = newStr + c;
  13.                         }
  14.                         System.out.println(newStr);
  15.                 }
  16.                 }
  17. }
复制代码

8 个回复

倒序浏览
学习学习!!!!!!
回复 使用道具 举报
不错 ,挺简洁的
回复 使用道具 举报
学习挺卖力,加油!!!
回复 使用道具 举报
学习挺卖力,加油!!!
回复 使用道具 举报
:o
如果 不考虑,单词 句子的意思,还可以减少很多
  1.         public static void main(String[] args) {
  2.                 test("this is a test");
  3.         }
  4.         public static void test(String str){
  5.            if(str!=null){
  6.                    for(int i=str.length()-1;i>=0;i--)
  7.                    {
  8.                            System.out.print(str.charAt(i));
  9.                    }
  10.                    System.out.println();
  11.                    }
  12.         }
  13. }
复制代码



回复 使用道具 举报
一句话解决  StringBuffer sb = new StringBufer(str);   System.out,println(sb.reverse());
回复 使用道具 举报
Melo 中级黑马 2015-5-29 21:31:48
8#
6666666666
回复 使用道具 举报
用String比较浪费内存,用StringBuffer省内存点,不过这点内存不足考虑
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马