Update for zero and negative numbers
This commit is contained in:
parent
e68334330e
commit
ce5ca17381
@ -7,7 +7,14 @@ class CountDigit{
|
|||||||
System.out.print("Enter the number: ");
|
System.out.print("Enter the number: ");
|
||||||
int number = sc.nextInt();
|
int number = sc.nextInt();
|
||||||
int digits = 0;
|
int digits = 0;
|
||||||
digits = (int)Math.floor(Math.log10(number) + 1);
|
if(number == 0)
|
||||||
System.out.println("The number of digits present in the number: " + digits);
|
{
|
||||||
|
System.out.println("The number of digits present in the number: 1");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digits = (int)Math.floor(Math.log10(Math.abs(number)) + 1);
|
||||||
|
System.out.println("The number of digits present in the number: " + digits);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user