You need to modify the lines
long count = 1L * MAX * MAX * MAX * MAX * MAX; // one more * MAX
...
int[] digits = new int[5]; // from [4]
char[] output = "00000".toCharArray(); // from 0000
...
for(int d = 4; d >=0; --d){ // from d = 3
More generally, if n
is the number of digits,
long count = 1L;
for( int i=0; i<n; i++ ) count *= MAX;
...
int[] digits = new int[n];
char[] output = new char[n];
Arrays.fill( output, '0' );
...
for(int d = n-1; d >=0; --d){