Skip to content

Commit 1364e2b

Browse files
committed
feat: Count total number of digits in an integer
🧠 Logic: - Given an integer `n = 467777777`, we divide it repeatedly by 10 to remove its last digit. - Each division operation indicates one digit processed, so we increment a `res` counter. - The loop continues until `n` becomes 0. - Finally, `res` holds the total number of digits in the original number (here, 9). Signed-off-by: Somesh diwan <[email protected]>
1 parent 4322c96 commit 1364e2b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Section7ConditionalStatements/src/countsDigits.java renamed to Section7ConditionalStatements/src/CountsDigits.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
public class countsDigits {
1+
public class CountsDigits {
22
public static void main(String[] args) {
33
int n=467777777;
4+
45
System.out.println(n/10);
6+
57
int res = 0;
6-
while (n>0)
7-
{
8+
while (n>0) {
89
n = n/10;
910
res++;
1011
}

0 commit comments

Comments
 (0)