How can i get this code to write all the possible permutation in the created txt i only get GRB in the text file after run
import java.util.Formatter; import java.util.*; import java.io.*; class Permutation { public static void main(String[] args) { String str = "RBG"; int n = str.length(); Permutation permutation = new Permutation(); permutation.permute(str, 0, n-1); } //permutation function private void permute(String str, int l, int r) { if (l == r) { try { Formatter form=new Formatter("/sdcard/Download/new.txt"); form.format(str); form.close();} catch (Exception e) { System.out.println("Error");}} else { for (int i = l; i <= r; i++) { str = swap(str,l,i); permute(str, l+1, r); str = swap(str,l,i); }}} private String swap(String a, int i, int j) { char temp; char[] charArray = a.toCharArray(); temp = charArray[i] ; charArray[i] = charArray[j]; charArray[j] = temp; return String.valueOf(charArray); } }