title: Converting int to string reduces time complexity of calculating its length
body: <p>The following code block:</p>
  
  <pre><code>Scanner in=new Scanner(System.in);
  int n=in.nextInt();
  //converting the integer to string and calculating
  //its length reduces the complexity
  //to O(n) as compared to O(n^2)
  String str=Integer.toString(n);
  int length=str.length();length-=1;
  </code></pre>
  
  <p>I found <a href="http://qa.geeksforgeeks.org/10856/you-are-asked-to-square-every-digit-of-a-number" rel="nofollow noreferrer">this code here</a>.</p>
  
  <p>My question is how does changing the int to string reduce the time complexity?</p>