H
horstiii1
Gast
Java:
public static void main(String[] args) {
System.out.println(new Matrix(2, 3, "a","a","b","b","c","c" ).toString());
}
public class Matrix {
int n_spalten;
int m_zeilen;
String[][] a;
public Matrix(int n_spalten, int m_zeilen, String... v) {
this.n_spalten = n_spalten;
this.m_zeilen = m_zeilen;
this.a = new String[m_zeilen][n_spalten];
for (int i = 0; i < v.length; i++) {
a[i / n_spalten][i % n_spalten] = v[i];
}
}
@Override
public String toString() {
return m_zeilen + "x" + n_spalten + "[" + Arrays.stream(a).map((t) -> {
return "[" + Arrays.stream(t).collect(Collectors.joining(",")) + "]";
}).collect(Collectors.joining(", ")) + "]";
}
}
Ergebnis:
Code:
3x2[[a,a], [b,b], [c,c]]
Ist das richtig??