⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
public class StrMirror {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("請輸入字符串:");
String str = sc.next();
System.out.println("str = " + str);
//String revStr = reverse1(str);
//System.out.println("revStr = " + revStr);
System.out.println("請輸入逆轉次數:");
int num = sc.nextInt();
for (int i = 0; i < num; i ++) {
str = str + reverse1(str);
}
System.out.println("mirror str = " + str);
}
public static String reverse1(String str) {
int length = str.length();
if (length <= 1) {
return str;
}
String left = str.substring(0, length / 2);
String right = str.substring(length / 2, length);
return reverse1(right) + reverse1(left);
}
}