Вы можете просто сохранить один StringBuilder
и добавить его по пути, печатая только один раз в конце:
int anzZeilen = 9;
int anzZahlen = 1;
StringBuilder msg = new StringBuilder();
for (int i=1; i <= 9; i++) {
msg.append(" ");
for (int j=1; j < anzZeilen; j++) {
msg.append(" ");
}
if (anzZahlen % 2 != 0) {
for (int x = 1; x <= anzZahlen; x++) {
msg.append(" ").append(x).append(" ");
}
}
msg.append("\n");
anzZahlen++;
anzZeilen--;
}
// now print the entire message, once
System.out.println(msg);