Count in base 2, 3, 4 etc in Java and output all permutations

Posted by tree-hacker on Stack Overflow See other posts from Stack Overflow or by tree-hacker
Published on 2012-09-12T21:25:49Z Indexed on 2012/09/12 21:38 UTC
Read the original article Hit count: 170

I want to write a function in Java that takes as input an integer and outputs every possible permutation of numbers up to that integer. For example:

f(1)

0

f(2) should output:

00 01 10 11

f(3) should output:

000 001 002 010 011 012 020 021 022 100 .... 220 221 222

That is it should output all 27 permutations of the digits of the numbers 0, 1, 2.

f(4) should output 0000 0001 0002 0003 0010 ... 3330 3331 3332 3333

f(4) should output 00000 00001 ... 44443 44444

I have been trying to solve this problem but cannot seem to work out how to do it and keep getting confused by how many loops I need. Does anyone know how to solve this problem? Thanks in advance.

© Stack Overflow or respective owner

Related posts about java

Related posts about binary