下列為Reverse class 的程式規範與其執行結果,試以遞迴(recursive)
的方式完成副程式reverse(int[] arr, int x),撰寫時,必須使用相同的參數
名稱與資料型態。reverse(int[] arr, int x)會回傳一個倒過來擺置的整數
串:arr[n-1], arr[n-2], … arr[x+1], arr[x],假設arr 內共有n 個元素,而
且x <= n。(25 分)
2 public class Reverse
3 {
4 public static String reverse(int[] arr, int x)
5 {
6
7 }
8
9 public static void main(String[] args)
10 {
11 int[] intArr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
12 String results = reverse(intArr, 2);
13 System.out.println(results);
14 System.out.println(reverse(intArr, 7));
15 }
16 }
10 9 8 7 6 5 4 3
10 9 8