黑马程序员技术交流社区
标题:
算法:字符串的倒序输出
[打印本页]
作者:
半世心修
时间:
2015-5-29 09:21
标题:
算法:字符串的倒序输出
又一个小算法:
public class Test {
public static void main(String args[]){
test("this is a test");
}
public static void test(String str){
if(str!=null){
String newStr = "";
for(int i=0;i<str.length();i++)
{
char c = str.charAt(str.length()-1-i);
System.out.println(str.length()-1-i);
newStr = newStr + c;
}
System.out.println(newStr);
}
}
}
复制代码
作者:
sjaiwl
时间:
2015-5-29 09:25
学习学习!!!!!!
作者:
mmakun
时间:
2015-5-29 09:51
不错 ,挺简洁的
作者:
张国江
时间:
2015-5-29 12:33
学习挺卖力,加油!!!
作者:
张国江
时间:
2015-5-29 12:40
学习挺卖力,加油!!!
作者:
微凉的暮色
时间:
2015-5-29 14:17
:o
如果 不考虑,单词 句子的意思,还可以减少很多
public static void main(String[] args) {
test("this is a test");
}
public static void test(String str){
if(str!=null){
for(int i=str.length()-1;i>=0;i--)
{
System.out.print(str.charAt(i));
}
System.out.println();
}
}
}
复制代码
作者:
wf111sxwf
时间:
2015-5-29 20:19
一句话解决 StringBuffer sb = new StringBufer(str); System.out,println(sb.reverse());
作者:
Melo
时间:
2015-5-29 21:31
6666666666
作者:
仅此一抹心醉
时间:
2015-5-29 21:49
用String比较浪费内存,用StringBuffer省内存点,不过这点内存不足考虑
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2