Java Program:

- To print total number of digits in a number

Example:

User Input: 15

Output:
Total number of digits : 2

import java.util.Scanner;
public class CountDigits {
  public static void main(String []args) {
    int num,count=0;
    Scanner userInput = new Scanner(System.in);
    System.out.print("Enter Your number : ");
    num = userInput.nextInt();

    while(num!=0) {
      num/=10;
      count++;
    }
    System.out.println("Total number of digits : "+count);
  }
}

Output:

  Enter Your number : 1132
  Total number of digits : 4
Program
number

Main Logic :

while(num!=0){
  num/=10;  // num=num/10
  count++;
}

Divide the number by 10 while your number becomes 0[ZERO]
& Just count how many times it divides the number to make it ZERO

Concept

Coming Soon !

Quick
Tutorial

Quote

Sometimes it’s the smallest decisions that can change your life forever.