Ho il seguente codice
il quale scorre una matrice quadrata diagonalmente dal basso verso l'altro e da sinistra verso destra.codice:String s; int NumRow = tabellaLettere.length; int NumColum = tabellaLettere[0].length; int righeteoriche = NumRow + NumColum - 1; for (int j = 0; j < righeteoriche; j++) { s = ""; int R; int C; if (j < NumRow) { R = j; C = 0; } else { R = NumRow - 1; C = j - NumRow + 1; } while (R >= 0 && C < NumColum) { s += tabellaLettere[R][C]; R--; C++; } System.out.println(s); }
Ad esempio avendo una matrice del tipo:
1 2 3
4 5 6
7 8 9
il risultato sono 6 stringhe del tipo:
1
42
753
86
9
Come potrei modificarlo per ottenere, invece, le stringhe:
3
62
951
84
7
?????
Grazie anticipatamente.

Rispondi quotando