|
Digit Counting
A Programming Pattern |
|
Prof. David Bernstein |
| Computer Science Department |
| bernstdh@jmu.edu |
Math.log10(7198) is approximately
3.8572118423168926 which is in the
interval \([3,4)\)Math.log10(462) is approximately
2.6646419755561257 which is in the
interval \([2,3)\)
/**
* Determine the number of digits in an integer.
*
* @param x The integer of interest
* @return The number of digits
*/
public static int digits(int x) {
return (int) Math.log10(x) + 1;
}
(int)Math.log10(156720) + 1 (i.e., 6) figure
salary