@@ -0,0 +1,1648 @@
+/*%0A4. %5BTests basic knowledge of recursion%5D %0A%0AWrite a recursive static Java method that accepts an array arr of integers argument %0Areturns a list of all permutations of these integers.%0A%0A(A permutation of a sequence of integers is a re-arrangement of the integers. %0AFor example, one permutation of  1, 3, 4, 8, 2 is 3, 1, 2, 8, 4.) %0AFor this problem, you may assume that the input array contains no duplicate entries. %0AYour method should return an ArrayList of int arrays.%0A%0ANext, test your method using a main method; %0Athe main method should pass in the following array: %5B1, 5, 4, 2%5D; %0Athen, it should print to the console the resulting list of permutations.%0A*/%0A%0A%0A%0Aclass QuestionFour0%0A%7B%0A%09public static void main(String%5B%5D args) %7B%0A%09%09System.out.println(%22Question Four%22);%0A%09%09// permutation(%22ABCD%22);%0A%09%09// for(String item : ret) %7B%0A%09%09// %09System.out.println(item);%0A%09%09// %7D%0A%09%09swap(%22ABCD%22);%0A%09%7D%0A%0A%09static void swap(String st) %7B%0A%09%09StringBuilder str = new StringBuilder(st);%0A%09%09for (int i = 0; i %3C str.length(); i++) %7B%0A%09%09%09for (int j = 0; j %3C str.length(); j++) %7B%0A%09%09%09%09if (j == i) %7B%0A%09%09%09%09%09continue;%09%09%09%0A%09%09%09%09%7D%0A%09%09%09%09char temp = str.charAt(j);%0A%09%09%09%09str.setCharAt(j, str.charAt(i));%0A%09%09%09%09str.setCharAt(i, temp);%0A%09%09%09%09System.out.println(str);%0A%0A%09%09%09%09%0A%09%09%09%7D%0A%0A%09%09%7D%0A%09%7D%0A%0A%09public static void permutation(String str) %7B %0A    %09permutation(%22%22, str); %0A%09%7D%09%0A%0A%09private static void permutation(String prefix, String str) %7B%0A%09%09// System.out.println(prefix + %22 -%3E %22 + str);%0A    %09int n = str.length();%0A    %09if (n == 0) System.out.println(prefix);%0A    %09else %7B%0A        %09for (int i = 0; i %3C n; i++)%0A            %09permutation(prefix + str.charAt(i), str.substring(0, i) + str.substring(i+1, n));%0A    %09%7D%0A%09%7D%0A%7D

Add permutation method.