Skip to content

Commit

Permalink
Reto mouredev#16 - LA ESCALERA [Media]
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenavarroenamoradotokio authored Sep 7, 2023
1 parent 8768c31 commit 4df69cb
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.retos.ej16;

public class jorgenavarroenamoradotokio {

public static void main(String[] args) {
drawStaircase(0);
drawStaircase(4);
drawStaircase(-4);
}

public static void drawStaircase(int steps) {
if (steps > 0) {
// Escalera ascendente de izquierda a derecha
for (int step = 0; step <= steps; step++) {
String spaces = " ".repeat(steps - step);
String stepDraw = (step == 0) ? "_" : "_|";
System.out.println(spaces + stepDraw);
}
} else if (steps < 0) {
// Escalera descendente de izquierda a derecha
for (int step = 0; step <= Math.abs(steps); step++) {
String spaces = " ".repeat((step * 2));
String stepDraw = (step == 0) ? "_" : "|_";
System.out.println(spaces + stepDraw);
}
} else {
System.out.println("__");
}
}

}

0 comments on commit 4df69cb

Please sign in to comment.