参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); String string = scanner.next(); scanner.close(); char[] ch = string.toCharArray(); daoZhi(ch, n); // 最终结果输出 for (char c : ch) { System.out.print(c); } } public static void daoZhi(char[] ch, int n) { if ((ch.length % 2 == 1 && n <= ch.length / 2 + 1) || (ch.length % 2 == 0 && n <= ch.length / 2)) { // 空行 System.out.println(); } else { // 交换 char s = ch[n - 1]; ch[n - 1] = ch[ch.length - n]; ch[ch.length - n ] = s; // 输出 for (char c : ch) { System.out.print(c); } System.out.println(); // 递归 daoZhi(ch, n - 1); } } }
0.0分
0 人评分