Update for zero and negative numbers

This commit is contained in:
Utsav1999 2020-07-26 01:31:34 +05:30
parent e68334330e
commit ce5ca17381

View File

@ -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);
}
} }
} }