Skip to content

Commit 33b982e

Browse files
authored
Merge pull request TheAlgorithms#1369 from Utsav1999/utsav-math
Added Count Digit program
2 parents 8ddbed6 + 7f944d9 commit 33b982e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Maths/CountDigit.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.util.*;
2+
package Maths;
3+
// count the number of digits in a number
4+
class CountDigit {
5+
public static void main(String args[]) {
6+
Scanner sc = new Scanner(System.in);
7+
System.out.print("Enter the number: ");
8+
int number = sc.nextInt();
9+
int digits = 0;
10+
if(number == 0)
11+
{
12+
System.out.println("The number of digits present in the number: 1");
13+
}
14+
else
15+
{
16+
digits = (int)Math.floor(Math.log10(Math.abs(number)) + 1);
17+
System.out.println("The number of digits present in the number: " + digits);
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)