Sort by

recency

|

5195 Discussions

|

  • + 0 comments

    // Use Java version 15. + First, I realized that the "#" character should be printed from 1 up to n each line. + Therefore, the number of spaces printed on each line equals n minus the number of "#" characters. + To reduce the number of System.out.println calls (which improves I/O effiency) we can use the StringBuilder with the repeat() method (available since Java 11).

    // Source Code: public static void staircase(int n) { // Write your code here StringBuilder sb = new StringBuilder(); for (int i = 0 ; i< n ; i++) {

        sb.append(" ".repeat(n-i-1))
        .append("#".repeat(i+1)).append("\n") ;
    }
    
    System.out.println(sb);
    
    
    
    
    }
    
  • + 0 comments
                                                                                              #
                                                                                             ##
                                                                                            ###
                                                                                           ####
                                                                                          #####
                                                                                         ######
                                                                                        #######
                                                                                       ########
                                                                                      #########
                                                                                     ##########
                                                                                    ###########
                                                                                   ############
                                                                                  #############
                                                                                 ##############
                                                                                ###############
                                                                               ################
                                                                              #################
                                                                             ##################
                                                                            ###################
                                                                           ####################
                                                                          #####################
                                                                         ######################
                                                                        #######################
                                                                       ########################
                                                                      #########################
                                                                     ##########################
                                                                    ###########################
                                                                   ############################
                                                                  #############################
                                                                 ##############################
                                                                ###############################
                                                               ################################
                                                              #################################
                                                             ##################################
                                                            ###################################
                                                           ####################################
                                                          #####################################
                                                         ######################################
                                                        #######################################
                                                       ########################################
                                                      #########################################
                                                     ##########################################
                                                    ###########################################
                                                   ############################################
                                                  #############################################
                                                 ##############################################
                                                ###############################################
                                               ################################################
                                              #################################################
                                             ##################################################
                                            ###################################################
                                           ####################################################
                                          #####################################################
                                         ######################################################
                                        #######################################################
                                       ########################################################
                                      #########################################################
                                     ##########################################################
                                    ###########################################################
                                   ############################################################
                                  #############################################################
                                 ##############################################################
                                ###############################################################
                               ################################################################
                              #################################################################
                             ##################################################################
                            ###################################################################
                           ####################################################################
                          #####################################################################
                         ######################################################################
                        #######################################################################
                       ########################################################################
                      #########################################################################
                     ##########################################################################
                    ###########################################################################
                   ############################################################################
                  #############################################################################
                 ##############################################################################
                ###############################################################################
               ################################################################################
              #################################################################################
             ##################################################################################
            ###################################################################################
           ####################################################################################
          #####################################################################################
         ######################################################################################
        #######################################################################################
       ########################################################################################
      #########################################################################################
     ##########################################################################################
    ###########################################################################################
    

    ############################################################################################ ############################################################################################# ##############################################################################################

    #
  • + 0 comments

    For Python3 Platform

    I wrote the code from scratch just to get more practice

    def staircase(n):
        for i in range(1,n+1):
            print(" "*(n-i) + "#"*i)
    
    n = int(input())
    
    staircase(n)
    
  • + 0 comments

    c++ solution:

    void staircase(int n){
       for ( int i = 1;i<=n;i++){
    	cout<< string(n-i, ' ');
    	cout<< string(i, '#')<< endl;
       }
    }
    
  • + 0 comments

    Python:

    def staircase(n): # Write your code here for i in range(1,n+1): text = '#'*i print(text.rjust(n))