write a program to input a number and print the total number of digits in it in Java
Answers
Answered by
4
Answer:
import java.util.*;
class digits{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number: ");
int n = sc.nextInt();
// variable c to count the digits;
int c = 0;
while(n > 0){
n = n/10;
// digits reduce by 1
// 453 / 10 = 45
// 45 /10 = 4
c++;
}
System.out.println(c);
}
}
Similar questions