non avendo una sfera di cristallo, non possiamo aiutarti se non fornisci dettagli completi. Certo che salta subito all'occhio quella funzione pow che usi tranquillamente negli indici dei vettori (l'ho "riscritta" per essere sicuri che ritorni un int) ed ho scritto una mini-classe (quello che hai postato tu è un metodo, non una classe), per provare il tuo metodo. Ho solo aggiunto un po' di graffe
codice:
package html.exercise;
/**
*
* @author Andrea
*/
public class Esercizio52 {
public static int pow (int b, int e) {
return (int)Math.pow(b, e);
}
public static StringBuffer[] creaTabellaTotale(int n, char[] a) {
StringBuffer[] tabella = new StringBuffer[ pow(26, n)];
for(int w =0; w < pow(26, n); w++) {
tabella[w] = new StringBuffer("");
}
for(int h = 1; h <= n ; h++){
for(int u =0; u < pow ( 26, h-1); u++) {
for (int j = 0; j<26; j++) {
for( int x =pow(26, n-h+1)*u + pow(26, n-h)*j; x< pow(26, n-h+1)*u + pow(26, n-h)*(j+1); x++) {
tabella[x] = tabella[x].append(a[j]);
}
}
}
}
return tabella;
}
public static void main (String[] args) {
char[] a = new char[] {
'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z'
};
StringBuffer[] tabella = creaTabellaTotale(3, a);
for (StringBuffer buf : tabella) {
System.out.println(buf);
}
}
}
brutto ma funziona. Certo si potrebbe migliorare (per esemopio: se passi un array di char che in qualche modo rappresentano il tuo alfabeto, perché passare la lunghezza dell'alfabeto? Passa solo l'array di char e la lunghezza dell'alfabeto è già determinata).
Occhio agli OutOfMemoryError... con uno Heap "standard" (non ho modificato il mio), esci già con un errore per n = 5