How to count the number of digits in any Input number other than negative numbers
By: Ganesh Iyer
import java.io.*;
class constplaceCount
{
int cnt;
int numPlace(int num)
{
while (num > 0 )
{
int r = num % 10;
cnt++;
num = num / 10;
System.out.println(\"The number\"+num);
}
return cnt;
}
}
class placeCount
{
public static void main(String[] args)
{
int cnt;
constplaceCount n = new constplaceCount( );
cnt = n.numPlace(50);
System.out.println(\"The count of the number places \"+cnt);
}
}
Archived Comments
1. exuanelov
View Tutorial By: exuanelov at 2017-04-27 09:52:21
2. cibqlyunuloki
View Tutorial By: cibqlyunuloki at 2017-04-27 08:53:55
3. avevapaiwufo
View Tutorial By: avevapaiwufo at 2017-04-27 08:53:26
4. edajajo
View Tutorial By: edajajo at 2017-04-27 08:19:36
5. oziforoduq
View Tutorial By: oziforoduq at 2017-04-27 07:58:40
6. auozoynuanula
View Tutorial By: auozoynuanula at 2017-04-27 07:42:40
7. azaxohi
View Tutorial By: azaxohi at 2017-04-27 06:48:06
8. aquierod
View Tutorial By: aquierod at 2017-04-27 06:19:59
9. it doesn't count for the values like 001 or 02 etc..
View Tutorial By: angesh at 2012-02-10 16:15:02
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java