- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Example
import java.util.Scanner; public class CountingDigitsInInteger { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int count = 0; System.out.println("Enter a number ::"); int num = sc.nextInt(); while(num!=0){ num = num/10; count++; } System.out.println("Number of digits in the entered integer are :: "+count); } }
Output
Enter a number :: 1254566 Number of digits in the entered integer are :: 7
- Related Articles
- Java Program to Count Number of Digits in an Integer
- Swift Program to Count Number of Digits in an Integer
- Haskell Program to Count Number of Digits in an Integer
- Kotlin Program to Count Number of Digits in an Integer
- Write a program in Python to count the number of digits in a given number N
- Golang Program to Count the Number of Digits in a Number
- Golang Program to count the number of flips to convert a given integer to another.
- Java program to count the number of consonants in a given sentence
- Java program to count the number of vowels in a given sentence
- How to count digits of given number? JavaScript
- C++ Program to Sum the digits of a given number
- Write a program in Python to count the total number of integer, float and object data types in a given series
- C Program to sum the digits of a given number in single statement
- Program to count number of stepping numbers of n digits in python
- Java Program to Count set bits in an integer

Advertisements