count the number of digits in an integer in java
// JAVA Code to count number of
// digits in an integer
import java.util.*;
class GFG {
static int countDigit(long n)
{
return (int)Math.floor(Math.log10(n) + 1);
}
/* Driver program to test above function */
public static void main(String[] args)
{
long n = 345289467;
System.out.print("Number of digits : " + countDigit(n));
}
}
// This code is contributed by Arnav Kr. Mandal.
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);
}
}