如何倒写语句?

[复制链接]
查看11 | 回复2 | 2008-1-18 16:36:34 | 显示全部楼层 |阅读模式
StringBuffer sb=new String("hello world!");sb.reverse();直接用reverse()方法,就能反转字符串楼主打算用“算法”去实现反转?那还不如用System.out.print("!dlrow olleh");来的容易。。。这个你总学过吧?
回复

使用道具 举报

千问 | 2008-1-18 16:36:34 | 显示全部楼层
很简单,用个for就可以:String s="hello world!";for(int i=s.length()-1;i>=0;i--)System.out.print(s.charAt(i));
回复

使用道具 举报

千问 | 2008-1-18 16:36:34 | 显示全部楼层
public String daoshu(String str) {String temp = "";for(int i=str.length()-1;i>=0;i--){ temp = temp + str.charAt(i);}return temp; }
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行