count the number of digits in an integer in java

Solutions on MaxInterview for count the number of digits in an integer in java by the best coders in the world

showing results for - "count the number of digits in an integer in java"
Iyed
20 Aug 2020
1import java.util.Scanner;
2public class CountingDigitsInInteger {
3   public static void main(String args[]){
4      Scanner sc = new Scanner(System.in);
5      int count = 0;
6      System.out.println("Enter a number ::");
7      int num = sc.nextInt();
8      while(num!=0){
9         num = num/10;
10         count++;
11      }
12      System.out.println("Number of digits in the entered integer are :: "+count);
13   }
14}