Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** PRECONDICIÓN: base IMPAR y MAYOR QUE 3
- *
- * Dada una base, devuelve el dibujo (String) del
- * correspondiente triángulo isósceles realizado
- * con asteriscos (y espacios en blanco).
- */
- public static String dibujarTriangulo(int base) {
- String triangulo = "";
- int altura = base / 2;
- for (int i = altura, k = 1; i >= 0; i--, k += 2) {
- for (int j = 1; j <= i; j++) {
- triangulo += " ";
- }
- for (int l = 1; l <= k; l++) {
- triangulo += "*";
- }
- triangulo += "\n";
- }
- return triangulo;
- }
Add Comment
Please, Sign In to add comment