Staircase Problem Solution

In the beginning of learning programing, Staircase problem become a common challenge which startup programmer must solve. The purpose of this challenge is simple. Just make staircase made of some character with the height you input.

Now let's begin, consider the n value is 5. Watch that its base and tallness are both equivalent to , and the picture is drawn utilizing # images and spaces. The last line isn't gone before by any spaces.


Write a program that prints a staircase of size . Remember The staircase is correct adjusted, made out of # images and spaces, and has a tallness and width of n=6.

Solution

import java.util.Scanner;

public class Solution {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Scanner in = new Scanner(System.in);
  int n = in.nextInt();
  for (int i=n;i>0;i--) {
   int j=(i-1);
   int k=j;
   for ( ;j>0;j--) {
    System.out.print(" ");
   }
   for (;k<n;k++) { 
    System.out.print("#");
   }
   System.out.print("\n");
  }
 }

}


Output

 

Comments

Popular posts from this blog

Quantization of Image Data Implementation in C#

Computer Graphics Project "Planet Orbit" Source Code with Glut OpenGL

Computer Graphics Project "MINION" Source Code with Glut OpenGL