Skip to content

Instantly share code, notes, and snippets.

@gusthavosouza
Last active August 11, 2016 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gusthavosouza/811a9669efea878b878393ea68366498 to your computer and use it in GitHub Desktop.
Save gusthavosouza/811a9669efea878b878393ea68366498 to your computer and use it in GitHub Desktop.
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