I'm writing code that prints you combination of numbers from 1 to n. In console it works perfectly fine, but i need to print it into file. What should i do?
Code:
public class Permutace {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("your number: ");
int N = sc.nextInt();
int[] sequence = new int[N];
for (int i = 0; i < N; i++) {
sequence[i] = i + 1;
}
permute(sequence, 0);
}
public static void permute(int[] a, int k){
if (k == a.length) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i]);
}
System.out.println();
} else {
for (int i = k; i < a.length; i++) {
int temp = a[k];
a[k] = a[i];
a[i] = temp;
permute(a, k + 1);
temp = a[k];
a[k] = a[i];
a[i] = temp;
}
}
}
}