-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExample7.java
More file actions
33 lines (25 loc) · 734 Bytes
/
Example7.java
File metadata and controls
33 lines (25 loc) · 734 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package applications.algorithms;
/** Category: Algorithms
* ID: FindNumberOfDigitsInInteger
* Description: Find the number of digits in a given integer
* Taken From:
* Details:
* We can get the number of digits contained in an integer by continuously
* dividing with 10 as long as the number is greater than 0
*/
public class Example7
{
public static void run(String[] args){
int number = 100;
int numberCopy = number;
int count = 0;
while(numberCopy > 0){
count++;
numberCopy /= 10;
}
System.out.println("Number of digits for "+number+" is: "+count);
}
public static void main(String[] args){
Example7.run(args);
}
}