From ce5ca1738117b01ea28de2df8cf982ffbff9fa32 Mon Sep 17 00:00:00 2001 From: Utsav1999 Date: Sun, 26 Jul 2020 01:31:34 +0530 Subject: [PATCH] Update for zero and negative numbers --- Maths/CountDigit.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Maths/CountDigit.java b/Maths/CountDigit.java index 2c3080e3..6610a35d 100644 --- a/Maths/CountDigit.java +++ b/Maths/CountDigit.java @@ -7,7 +7,14 @@ class CountDigit{ System.out.print("Enter the number: "); int number = sc.nextInt(); int digits = 0; - digits = (int)Math.floor(Math.log10(number) + 1); - System.out.println("The number of digits present in the number: " + digits); + if(number == 0) + { + 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); + } } } \ No newline at end of file