counting number of digits

 counting number of digits

Problem Description


Java program to count the number of digits in a number

Logic Test Case 1


Input (stdin)

1204


Expected Output


4

Logic Test Case 2


Input (stdin)

523678


Expected Output


6




CODE AREA

import java.io.*;

import java.util.*;

public class TestClass {

public static void main(String[] args)

     {

       Scanner g=new Scanner(System.in);

       int n,r=0;

       n=g.nextInt();

       while(n!=0)

       { 

         n/=10;

         ++r;

       } 

       System.out.print(r);

}

}

Post a Comment

0 Comments