DESKTOP-FKKMCTR_20200905-张森
所遇问题
1.倒叙输出一个字符串?
public class Base {
private static void a(String str) {
char[] chr = str.toCharArray();
for (int i = chr.length-1 ; i >= 0; i--) {
System.out.print(chr[i]);
}
System.out.println("\t");
}
private static void b(String str) {
if (str.length() == 1)
System.out.println(str);
else {
String subString1 = str.substring(0, str.length() - 1);
String subString2 = str.substring(str.length() - 1);
System.out.print(subString2);
b(subString1);
}
}
private static void c(String str) {
StringBuffer buffer = new StringBuffer(str);
System.out.println(buffer.reverse());
}
private static void d(String str) {
StringBuffer a = new StringBuffer();
String subString2 = "";
for (int i = str.length(); i > 0; i--) {
subString2 = str.substring(i - 1, i);
a.append(subString2);
}
System.out.print( a);
}
public static void main(String[] args) {
String str = "abcd";
a(str);
b(str);
c(str);
d(str);
}
}
吐槽
有时间你的眼睛看到的并不是你所知道的,只有你真正的去写得时候,你才会发现好多代码你可以看的懂,但是就是写不出来。所以以后有时间就在纸上写吧。毕竟朱熹曾经说过"纸上得来终觉浅,绝知此事要躬行。"
点赞