Skip to main content
Syntax correction
Source Link
Sahil
  • 1k
  • 9
  • 19

no String API, no utils, no type conversion, just pure java iteration ->

public static int getNumberOfDigits(int input) { int numOfDigitnumOfDigits = 1; int base = 1; while (input >= base * 10) { base = base * 10; numOfDigit++;numOfDigits++; } return numOfDigit;numOfDigits; } 

You can go long for bigger values if you please.

no String API, no utils, no type conversion, just pure java iteration ->

public static int getNumberOfDigits(int input) { int numOfDigit = 1; int base = 1; while (input >= base * 10) { base = base * 10; numOfDigit++; } return numOfDigit; } 

You can go long for bigger values if you please.

no String API, no utils, no type conversion, just pure java iteration ->

public static int getNumberOfDigits(int input) { int numOfDigits = 1; int base = 1; while (input >= base * 10) { base = base * 10; numOfDigits++; } return numOfDigits; } 

You can go long for bigger values if you please.

Syntax correction
Source Link
Sahil
  • 1k
  • 9
  • 19

no String API, no utils, no type conversion, just pure java iteration ->

public static int getNumberOfDigits(int input) { int numOfDigit = 1; int base = 1; while (input >= base * 10) { base = base * 10; numOfDigit++; } return numOfDigit;  } 

You can usego long for bigger values if you please. }

no String API, no utils, no type conversion, just pure java iteration ->

public static int getNumberOfDigits(int input) { int numOfDigit = 1; int base = 1; while (input >= base * 10) { base = base * 10; numOfDigit++; } return numOfDigit; 

You can use long for bigger values if you please. }

no String API, no utils, no type conversion, just pure java iteration ->

public static int getNumberOfDigits(int input) { int numOfDigit = 1; int base = 1; while (input >= base * 10) { base = base * 10; numOfDigit++; } return numOfDigit;  } 

You can go long for bigger values if you please.

Source Link
Sahil
  • 1k
  • 9
  • 19

no String API, no utils, no type conversion, just pure java iteration ->

public static int getNumberOfDigits(int input) { int numOfDigit = 1; int base = 1; while (input >= base * 10) { base = base * 10; numOfDigit++; } return numOfDigit; 

You can use long for bigger values if you please. }