Algorithm for Digits Are Present in the Number:
step 1: Set c=0
step 2: Read num
step 3: Repeat through step-5 while num greater than 0
step 4: c=c+1
step 5: num=num/10
step 6: Print c
Step 7: Exit
Here is the Java Example for Digits Are Present in the Number:
import java.util.Scanner;
public class DigitCount
{
int count(int num)
{
if(num>=0 && num<=9)
return 1;
else
return 1+count(num /10);
}
public static void main(String args[])
{
int c,num;
Scanner sl=new Scanner(System.in);
System.out.print("Enter A Number : ");
num=sl.nextInt();
DigitCount d=new DigitCount();
c=d.count(num);
System.out.println("Number of Digit is "+c);
}
}