How to count the number of digits in any Input number other than negative numbers

By: Ganesh Iyer Viewed: 154365 times  Printer Friendly Format    


import java.io.*;


class constplaceCount
{
   int cnt;

  int numPlace(int num)
  {

     while (num > 0 )

      {

         int r = num % 10;
         cnt++;

         num = num / 10;
         System.out.println(\"The number\"+num);

      }

         return cnt;
   }

}


class placeCount
{
      public static void main(String[] args)
      {

        int cnt;

        constplaceCount n = new constplaceCount( );

        cnt = n.numPlace(50);

        System.out.println(\"The count of the number places \"+cnt);

      }

}


Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial

Subscribe to Tutorials

Related Tutorials

Archived Comments

1. it doesn't count for the values like 001 or 02 et
View Tutorial          By: angesh at 2012-02-10 16:15:02

2. aquierod
View Tutorial          By: aquierod at 2017-04-27 06:19:59

3. azaxohi
View Tutorial          By: azaxohi at 2017-04-27 06:48:06

4. auozoynuanula
View Tutorial          By: auozoynuanula at 2017-04-27 07:42:40

5. oziforoduq
View Tutorial          By: oziforoduq at 2017-04-27 07:58:40

6. edajajo
View Tutorial          By: edajajo at 2017-04-27 08:19:36

7. avevapaiwufo
View Tutorial          By: avevapaiwufo at 2017-04-27 08:53:26

8. cibqlyunuloki
View Tutorial          By: cibqlyunuloki at 2017-04-27 08:53:55

9. exuanelov
View Tutorial          By: exuanelov at 2017-04-27 09:52:21