I have a java program which count the digits in the integer using for loop
it returns me the count as count of digit minus 1
For eg.if i enter 6 digit integer it returns count of 5
if I enter 10 digit integer it returns count of 9
public class DigitCount {
public static void main(String[] args) {
int a=123456;
int count=0;
for (int i=0;i<=a;i++){
a=a/10;
count++;
}
System.out.println(" numb of digits are : "+ count);
}
}
New contributor
mangeshplusplus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.