Sort by

recency

|

5106 Discussions

|

  • + 0 comments

    For Java 11 and above :

    public static void staircase(int n) {
    // Write your code here
    String s=" "; String hash = "#"; 
    for(int i=1; i<=n; i++) {
        System.out.print(s.repeat(n-i));
    
        System.out.println(hash.repeat(i)); } }
    
  • + 0 comments

    In Python:

    def staircase(n):
        base = n
        spaces = (base - 1)
        for b in range(1,base+1):
            print(' '*spaces +'#'*b)
            spaces -= 1
    
  • + 0 comments

    very nice information thanks

  • + 0 comments

    From a java perspective a solution would be like below:

        public static void staircase(int n) {
            IntStream.range(1, n+1).forEach(i -> {
                printChars((n-i), " ");
                printChars(i, "#"); 
                System.out.println("");
            });
        }
        
        public static void printChars(int count, String c) {
            for (int i = 0; i < count; i ++) {
               System.out.print(c);
            }
        }
    
  • + 0 comments

    Just like a staircase, some dirty pick-up lines have the perfect steps to get your attention. But hey, unlike those lines, I promise I’ll help clean up your space and leave it spotless! Let's make sure your staircase and home are as clean as your best pick-up lines are smooth!