DESKTOP-7803S27_20200905-吴远亮
问题
倒序输出一个字符串
解决方法
方法一:
public class Reverse {
public static void main(String[] args) {
String s="luoxiancheng";
StringBuffer buffer=new StringBuffer(s);
StringBuffer ss=buffer.reverse();
String st=ss.toString();
System.out.println(st);
}
}
方法一:
public class BianChengT1 {
public String reverse(String s ) {
int n=s.length();
if(n<=0) {
throw new IllegalArgumentException("参数不规范");
}
char[] ch=new char[n];
for(int x=n-1;x>=0;x--) {
ch[x]=s.charAt(n-1-x);
}
return String.valueOf(ch);
}
public static void main(String[] args) {
BianChengT1 bct=new BianChengT1();
String s="haihahdahaaf";
String ss=bct.reverse(s);
System.out.println(ss);
}
}
吐槽
最近学的很多方法都不熟练,还需要多加练习
近期评论