by Dinesh Thakur Category: Control Structures

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;
                    return 1+count(num /10);
               public static void main(String args[])
                         int c,num;
                   Scanner sl=new Scanner(;
                   System.out.print("Enter A Number : ");
                   DigitCount d=new DigitCount();
                   System.out.println("Number of Digit is "+c);

Digits Are Present in the Number

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles