title: Count and display ways to climb staircase java
body: <p>I wrote some code to count and also print the number of ways to climb a given staircase with <code>n</code> steps.</p>
  
  <p>It is only possible to climb 1 or 2 stairs at a time. I know this is a known interview question and I have some code I wrote to share with you.</p>
  
  <p>The problem is i am missing a lot of sequences. Can you please review and help me understand what logic I am missing? Thanks for your help</p>
  
  <p>My code:</p>
  
  <pre><code>/**
   * 
   */
  package prep;
  
  /**
   * @author rohandalvi
   *
   */
  public class generateAllPermutations {
  
      /**
       * @param args
       */
      static int totalCounter = 0;
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          int numberOfStairs = 10;
          int countSoFar = 0;
          String path = "";
          for(int i=1;i&lt;3;i++){
              path = ""+i;
              displayAllPerms(numberOfStairs, i, path);
          }
          System.out.println("Total combinations found "+totalCounter);
      }
  
      public static void displayAllPerms(int n,int countSoFar,String s){
          if(countSoFar &gt; n) return;
          else if(countSoFar &lt; n){
              for(int i=1;i&lt;3;i++){
                  s+=" "+i;
                  countSoFar+=i;
                  displayAllPerms(n, countSoFar, s);
              }
          }else{
              System.out.println("Found combination "+s);
              totalCounter++;
              return;
          }
      }
  
  }
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>Found combination 1 1 1 1 1 1 1 1 1 1
  Found combination 1 1 1 1 1 1 1 1 2
  Found combination 1 1 1 1 1 1 1 2 1
  Found combination 1 1 1 1 1 1 2 1 1
  Found combination 1 1 1 1 1 2 1 1 1
  Found combination 1 1 1 1 1 2 1 2
  Found combination 1 1 1 1 2 1 1 1 1
  Found combination 1 1 1 1 2 1 1 2
  Found combination 1 1 1 1 2 1 2 1
  Found combination 1 1 1 2 1 1 1 1 1
  Found combination 1 1 1 2 1 1 1 2
  Found combination 1 1 1 2 1 1 2 1
  Found combination 1 1 1 2 1 2 1 1
  Found combination 1 1 2 1 1 1 1 1 1
  Found combination 1 1 2 1 1 1 1 2
  Found combination 1 1 2 1 1 1 2 1
  Found combination 1 1 2 1 1 2 1 1
  Found combination 1 1 2 1 2 1 1 1
  Found combination 1 1 2 1 2 1 2
  Found combination 2 1 1 1 1 1 1 1 1
  Found combination 2 1 1 1 1 1 1 2
  Found combination 2 1 1 1 1 1 2 1
  Found combination 2 1 1 1 1 2 1 1
  Found combination 2 1 1 1 2 1 1 1
  Found combination 2 1 1 1 2 1 2
  Found combination 2 1 1 2 1 1 1 1
  Found combination 2 1 1 2 1 1 2
  Found combination 2 1 1 2 1 2 1
  Found combination 2 1 2 1 1 1 1 1
  Found combination 2 1 2 1 1 1 2
  Found combination 2 1 2 1 1 2 1
  Found combination 2 1 2 1 2 1 1
  </code></pre>
  
  <p>Basically, I am missing combinations like:</p>
  
  <pre><code>2 2 2 2 2
  </code></pre>
  
  <p>And a lot more combinations, basically all starting with 2 2 </p>