Raga ecco il programma quasi completato
codice:
import java.util.*;
public class CalcolaParole
{
public static void main(String[] args)
{
String number = "3342398";
String string = "";
String stringT = "";
char[][] matrice = new char[7][4];
for (byte i = 0; i < number.length(); i++)
{
switch (Byte.valueOf(number.substring(i,i+1)).byteValue())
{
case 2:
matrice[i][0] = 'A';
matrice[i][1] = 'B';
matrice[i][2] = 'C';
matrice[i][3] = ' ';
break;
case 3:
matrice[i][0] = 'D';
matrice[i][1] = 'E';
matrice[i][2] = 'F';
matrice[i][3] = ' ';
break;
case 4:
matrice[i][0] = 'G';
matrice[i][1] = 'H';
matrice[i][2] = 'I';
matrice[i][3] = ' ';
break;
case 5:
matrice[i][0] = 'J';
matrice[i][1] = 'K';
matrice[i][2] = 'L';
matrice[i][3] = ' ';
break;
case 6:
matrice[i][0] = 'M';
matrice[i][1] = 'N';
matrice[i][2] = 'O';
matrice[i][3] = ' ';
break;
case 7:
matrice[i][0] = 'P';
matrice[i][1] = 'Q';
matrice[i][2] = 'R';
matrice[i][3] = 'S';
break;
case 8:
matrice[i][0] = 'T';
matrice[i][1] = 'U';
matrice[i][2] = 'V';
matrice[i][3] = ' ';
break;
case 9:
matrice[i][0] = 'W';
matrice[i][1] = 'X';
matrice[i][2] = 'Y';
matrice[i][3] = 'Z';
}
}
int cont = 0;
for (byte g = 0; g < 4; g++)
for (byte f = 0; f < 4; f++)
for (byte e = 0; e < 4; e++)
for (byte d = 0; d < 4; d++)
for (byte c = 0; c < 4; c++)
for (byte b = 0; b < 4; b++)
for (byte a = 0; a < 4; a++)
{
string += matrice[0][g];
string += matrice[1][f];
string += matrice[2][e];
string += matrice[3][d];
string += matrice[4][c];
string += matrice[5][b];
string += matrice[6][a];
if (string.indexOf(' ') != -1)
{
System.out.printf("%s\n",string);
cont++;
}
string = "";
}
System.out.print(cont);
}
}
L'unico problema è che la condizione evidenziata in grassetto non funziona come dovrebbe... mi spiego meglio. Siccome nella matrice di caratteri ci sono alcuni spazi vuoti, voglio evitare che le stringhe che si vanno a formare appaiano a video se contengono spazi vuoti... ma anche con quella condizione, mi appaiono le stringhe con caratteri vuoti. Perchè non funziona come dovrebbe? :confuso: