Programming Tutorials

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

By: Ganesh Iyer in Java Tutorials on 2009-05-28  

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);

      }

}





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)