Sunday, September 2, 2012

JAVA Program to count digits in a number

Finding the number of digits in a number using a Java program was never been that easy. Here is how you can finding the number of digits in a number using a simple Java program.

public class CountDigit
{
 public static void main(String args[])
 {
                if(args.length!=1)
  {
   System.out.println("1 Argument Required..");
   return;
  }
               
  int no=Integer.parseInt(args[0]);
                int cnt=0;
                while(no>0)
                {
   cnt++;
   no=no/10;
                }
                System.out.println("\n Total Digits are : " + cnt);
 }
}


EmoticonEmoticon