forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reto mouredev#16 - LA ESCALERA [Media]
- Loading branch information
1 parent
8768c31
commit 4df69cb
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
Retos/Reto #16 - LA ESCALERA [Media]/java/jorgenavarroenamoradotokio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("__"); | ||
} | ||
} | ||
|
||
} |