rsvaco

CCDIK4ai triangulo

Jan 8th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.58 KB | None | 0 0
  1. /** PRECONDICIÓN: base IMPAR y MAYOR QUE 3
  2.  *
  3.  *  Dada una base, devuelve el dibujo (String) del
  4.  *  correspondiente triángulo isósceles realizado
  5.  *  con asteriscos (y espacios en blanco).
  6. */
  7. public static String dibujarTriangulo(int base) {
  8.     String triangulo = "";
  9.     int altura = base / 2;
  10.     for (int i = altura, k  = 1; i >= 0; i--, k += 2) {
  11.         for (int j = 1; j <= i; j++) {
  12.             triangulo += " ";
  13.         }
  14.         for (int l = 1; l <= k; l++) {
  15.             triangulo += "*";
  16.         }
  17.         triangulo += "\n";
  18.     }
  19.     return triangulo;
  20. }
Add Comment
Please, Sign In to add comment