Java:
public static int[][] punktProdukt(int[][] t1, int[][] t2) {
int c[][] = new int[t1.length][t1[0].length];
for (int i = 0; i < t1.length; i++) {
for (int j = 0; j < t1.length; j++) {
c[i][j] = t1[i][j] * t2[i][j];
}
}
return c;
}
public static int[][] punktPotenz(int[][] t, int n) {
int[][] neu = new int[t.length][];
neu = t;
if (n > 1) {
n -= 1;
neu = punktProdukt(neu, t);
}
return neu;
}
Bsp:
1 2 3 wird zu -> 1 8 27
4 5 6 64 125 216
7 8 9 343 512 729
bei punktPotenz(t1, 3).
1*1*1 2*2*2 usw. Will das Rekursiv mit der Vorgänger-Methode lösen, aber mein t oder neu Feld würde dann immer neue zugewiesen werden. Wie behalte ich das T-Feld als Variable?