alarm
Ask a question for free
Computer Science
Akakij

Write a program to input a number and print the total number of digits in it in Java​

answers: 1
Register to add an answer
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);

   }

}

119
Maurer Claus
For answers need to register.
Contacts
mail@expertinstudy.com
Feedback
Expert in study
About us
For new users
For new experts
Terms and Conditions