First of all, I have this input:
[[0.0, 1.0, 0.6666666666666666, -0.3333333333333333, 0.0, 0.0, 1.3333333333333333], [1.0, 0.0, -0.3333333333333333, 0.6666666666666666, 0.0, 0.0, 3.3333333333333335], [0.0, 0.0, -1.0, 1.0, 1.0, 0.0, 3.0], [0.0, 0.0, -0.6666666666666666, 0.3333333333333333, 0.0, 1.0, 0.6666666666666667], [0.0, 0.0, -0.3333333333333333, -1.3333333333333333, 0.0, 0.0, -12.666666666666666]];
Then I want to output this input formatted. There are some rules:
- Replace
[for""; - Replace
]for"\n"; - Replace
,for""; // Remove commas between elements - Replace
"."for","; // Change dot to comma - Truncate at the 2nd decimal place; // 1.33333 -> 1.33
So, here's my code for while:
@Override
public String toString() {
StringBuilder sb = new StringBuilder("\n");
sb.append("\n").append(numbersOfExmaple.toString()
.replaceAll("\\[", "")
.replaceAll("\\]", "\n")
.replaceAll(",", "")
.replaceAll("\\.", ","));
// String.format isn't working...
return sb.toString();
}
Actually the output is (note there's a whitespace in the beggining, I want to remove it also):
0,0 1,0 0,6666666666666666 -0,3333333333333333 0,0 0,0 1,3333333333333333
1,0 0,0 -0,3333333333333333 0,6666666666666666 0,0 0,0 3,3333333333333335
0,0 0,0 -1,0 1,0 1,0 0,0 3,0
0,0 0,0 -0,6666666666666666 0,3333333333333333 0,0 1,0 0,6666666666666667
0,0 0,0 -0,3333333333333333 -1,3333333333333333 0,0 0,0 -12,666666666666666
Expected output:
0,00 1,00 0,67 -0,33 0,00 0,00 1,33
1,00 0,00 -0,33 0,67 0,00 0,00 3,33
0,00 0,00 -1,00 1,00 1,00 0,00 3,00
0,00 0,00 -0,67 0,33 0,00 1,00 0,67
0,00 0,00 -0,33 -1,33 0,00 0,00 -12,67