Skip to content

Commit a88e59b

Browse files
committed
feat: Count the number of digits in a given number
🧠 Logic: - Take integer input `n`. - Initialize counter `count = 0`. - Use a `while` loop to repeatedly divide `n` by 10. - Each division removes the last digit. - Increment `count` on each iteration. - When `n` becomes 0, `count` holds the total number of digits. Signed-off-by: Somesh diwan <[email protected]>
1 parent 9bc05e9 commit a88e59b

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

Section8LoopAB/src/CountDigitsOfNumbers.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public static void main(String[] args) {
88
int n = scan.nextInt();
99

1010
int count = 0;
11-
12-
while(n>0){
11+
while(n>0) {
1312
n = n/10;
1413
count++;
1514
}

0 commit comments

Comments
 (0)