Print a Staircase of Size N

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
       
       
       String k = "#";
       String sum = "";
       for(int i=0;i<n;i++)
       {
           sum = sum + k;
           System.out.format("%"+n+"s \n",sum);
       }
       
    }
   
   
}

Output:

     #
    ##
   ###
  ####
 #####
######
Interview Questions: 

Search