title: Adding square of the digits in java
body: <p>Recently i attended one interview there they asked me to write a program like below,</p>
  
  <p>A number chain is created by continously adding the square of the digits in a number
  to form a new number untill its has been seen before.</p>
  
  <p>example :</p>
  
  <p>44 -> 32 -> 13-> 10-> 1</p>
  
  <p>85->89->145->42->20->4->16->37->58->89 </p>
  
  <p>therefore any chain arrives at 1 or 89 will become stuck in endless loop.
  what is most amazing is that every starting number will eventually arrive at 1 or 89.
  write a program to count the starting number below 10000 will arrive at 89?</p>
  
  <p>I wrote programs like below,</p>
  
  <pre><code>int num =44;
          int array[] = new int[100];
          int power=0;
          while(num &gt; 0)
          {
              int mod = num % 10;
              int div = num /10;
              int sum =(mod * mod) + (div * div);
  
              num =sum;
  
              System.out.print(" =&gt; "+sum);
  
              if(array.equals(sum)) 
                  // should not use any functions like Arrays.asList(array).contains(sum);
                  return; 
              else
              {
                  //System.out.println("else");
                  array[power++] =sum;
              }
  
          }
  </code></pre>
  
  <p>I know that above program not satisfy their requirements.Some one tell me good code snip to make them code satisfaction(If same question ask in future).?</p>
  
  <p><strong>Note</strong> : <code>should not use any function or import. Only logic is need.</code></p>