Skip to content

Commit ce5ca17

Browse files
committed
Update for zero and negative numbers
1 parent e683343 commit ce5ca17

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Maths/CountDigit.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ public static void main(String args[]){
77
System.out.print("Enter the number: ");
88
int number = sc.nextInt();
99
int digits = 0;
10-
digits = (int)Math.floor(Math.log10(number) + 1);
11-
System.out.println("The number of digits present in the number: " + digits);
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+
}
1219
}
1320
}

0 commit comments

Comments
 (0)