Untitled
unknown
plain_text
a year ago
1.4 kB
11
Indexable
public class Berge {
public static void main(String[] args) {
test();
}
public static void test() {
zeichneBerge(5, 3, 7);
System.out.println();
zeichneBerge(3, 5, 9);
}
public static void zeichneBerge(int w1, int w2, int w3) {
int h1 = (w1 + 1) / 2;
int h2 = (w2 + 1) / 2;
int h3 = (w3 + 1) / 2;
int maxH = (h1 > h2) ? ((h1 > h3) ? h1 : h3) : ((h2 > h3) ? h2 : h3);
for (int i = 0; i < maxH; i++) {
zeichneZeile(w1, h1, i, maxH, '*');
System.out.print(" ");
zeichneZeile(w2, h2, i, maxH, '#');
System.out.print(" ");
zeichneZeile(w3, h3, i, maxH, 'o');
System.out.println();
}
}
public static void zeichneZeile(int w, int h, int currentRow, int maxH, char zeichen) {
int currentHeight = h - (maxH - currentRow - 1);
if (currentHeight > 0) {
int currentWidth = (2 * currentHeight) - 1;
int padding = (w - currentWidth) / 2;
for (int i = 0; i < padding; i++) System.out.print(" ");
for (int i = 0; i < currentWidth; i++) System.out.print(zeichen);
for (int i = 0; i < padding; i++) System.out.print(" ");
} else {
for (int i = 0; i < w; i++) System.out.print(" ");
}
}
}
Editor is loading...
Leave a Comment