Java program to Count the number of digits in a given integer

Read a number from user. Create an integer (count) initialize it with 0. Divide the number with 10. till the number is 0 and for each turn increment the count.


import java.util.Scanner;
public class CountingDigitsInInteger {
   public static void main(String args[]){
      Scanner sc = new Scanner(;
      int count = 0;
      System.out.println("Enter a number ::");
      int num = sc.nextInt();
         num = num/10;
      System.out.println("Number of digits in the entered integer are :: "+count);


Enter a number ::
Number of digits in the entered integer are :: 7

Updated on: 13-Mar-2020

15K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started