package stage_0;
public class reverse {
public static void main(String[] args) {
StringBuffer a = new StringBuffer(" tset a si sihT");
reverse c = new reverse();
c.pig(a);
}
public void pig(StringBuffer a) {
StringBuffer b = new StringBuffer();
for (int i = 0; i < a.length(); i++) {
b.insert(0, a.charAt(i));
}
System.out.println(b);
}
}
看下
1
public class Test {
public static void main(String[] args) {
StringBuffer test=new StringBuffer("This is a test");
test.reverse();
System.out.println(test);
}
}
可以不
看看怎么做
1
666
哈哈哈 路过瞅瞅
谢谢
public class Str {
public static void main(String[] args) {
String a ="This is a test";
char [] b = a.toCharArray();
for(int i=b.length-1;i>=0;i--) {
System.out.print(b);
}
}
}
本帖最后由 blackroot 于 2018-9-25 13:57 编辑
cnkizy 发表于 2017-5-6 12:35
直接用Stack啊,或者一个for倒序输出也可以啊,for(int i=txt.length-1;i>=0;i--)print(txt.charAt(i));
字符串没有length属性,只有length().
cnkizy 发表于 2017-5-6 12:35
直接用Stack啊,或者一个for倒序输出也可以啊,for(int i=txt.length-1;i>=0;i--)print(txt.charAt(i));
字符串没有length,只有length()
public class TestStr{
public static void main(String arg[]){
String str = "this is a test";
StringBuffer sb = new StringBuffer(str);
sb.reverse();
System.out.print(sb);
}
}
6666
学习学习
public class Test1{
public static void main(String []args) {
StringBuffer a = new StringBuffer("This is a test");
StringBuffer b = a.reverse();
System.out.println(b);
}
}
public class Test1{
public static void main(String []args) {
String s = "This is a test";
for(int i=s.length()-1;i>=0;i--) {
System.out.print(s.charAt(i));
}
}
}
StringBuffer str1 = new StringBuffer("This is a text");
str1.reverse();
System.out.println(str1);
asdad a
6666