Last active
August 11, 2016 14:13
-
-
Save gusthavosouza/811a9669efea878b878393ea68366498 to your computer and use it in GitHub Desktop.
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
public class StairCase { | |
public static void main(String[] args) { | |
stairCase(10); | |
// output | |
// # | |
// ## | |
// ### | |
// #### | |
// ##### | |
// ###### | |
// ####### | |
// ######## | |
// ######### | |
//########## | |
} | |
static void stairCase (int n) { | |
if (n < 0) | |
return; | |
StringBuilder sb = new StringBuilder(); | |
for (int i = 1; i <= n; i++) { | |
for (int k = (n-i); k > 0; k--) | |
sb.append(" "); | |
for (int j = 1; j <= i; j++) | |
sb.append("#"); | |
System.out.println(sb.toString()); | |
sb.setLength(0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment