Skip to content

Instantly share code, notes, and snippets.

@slavaceornea
Last active June 3, 2016 14:37
Show Gist options
  • Save slavaceornea/e376efb52a781a316097105652452b01 to your computer and use it in GitHub Desktop.
Save slavaceornea/e376efb52a781a316097105652452b01 to your computer and use it in GitHub Desktop.
Java class outputs a staircase structure of height n that it gets from stdin.
import java.util.Scanner;
/**
*
* @author Slava
*
* Your teacher has given you the task of drawing a staircase structure. Being an expert programmer, you decided to make a program to draw it for you instead. Given the required height, can you print a staircase as shown in the example?
*
* Input
* You are given an integer depicting the height of the staircase.
*
* Output
* Print a staircase of height that consists of # symbols and spaces. For example for, here's a staircase of that height:
*
* #
* ##
* ###
* ####
* #####
* ######
*
* Note: The last line has 0 spaces before it.
*
*/
public class Staircase {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n - i - 1; j++)
{
System.out.print(" ");
}
for(int j = 0; j < i + 1; j++)
{
System.out.print("#");
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment