Given a number the task is to find out the number of digits present in the number.
Example 1: Let us take a number 3412. Here total number of digits is 5.
Java
import java.util.*;
public class DigitCount
{
public static void main(String args[])
{
int n=0,count=0;
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
n=sc.nextInt();
while(n>0)
{
count++;
n=n/10;
}
System.out.println("It is a "+count+" digit number");
}
}Java