title: sum of first and last digit in the integer
body: <p>The method written in the below code needs to take integer and result sum of 1st digit and last digit in the integer. </p>
  
  <p>NOTE: The reason i am asking this question though i got to know the correct solution is i need to understand why my code is not working also as that makes me a better programmer please help.</p>
  
  <pre><code>public class FirstLastDigitSum {
      public static int sumFirstAndLastDigit(int number)//to add first and last 
  //digits of a given interger
      {
          int firstdigit=0;
          int lastdigit=0;
  
          if(number&gt;=0 &amp;&amp; number&lt;=9)
          {
              return number+number;
          }
  
          else if(number&gt;9)
          {
              lastdigit=number%10;
              while(number&gt;0)
              {
                  number/=10;
                  if(number&lt;=9 &amp; number&gt;=0){
                      firstdigit=number;
                  }
  
              }
              return firstdigit+lastdigit;
          }
          else
          return -1;
      }
      public static void main(String[] args)
      {
          System.out.println(sumFirstAndLastDigit(121));
      }
  }
  </code></pre>
  
  <p>In the above code if i keep number/=10 after if block like below</p>
  
  <pre><code>if(number&lt;=9 &amp; number&gt;=0){
                          firstdigit=number;
                      }
  number/=10;
  </code></pre>
  
  <p>then my code is giving proper results. like if i input 121 to the method as first digit is 1 and second digit is 1 it is summing both and giving me result 2. which is absolutely correct</p>
  
  <p>But if keep number/=10 above the if block like below</p>
  
  <pre><code> number/=10;
      if(number&lt;=9 &amp; number&gt;=0){
                              firstdigit=number;
                          }
  </code></pre>
  
  <p>Then my code is not giving proper result it is giving only last number which is 1. </p>
  
  <p>I am not at all understanding why this is happening can any one explain please.</p>