Wednesday, September 19

Calculate the number of digits in the number using division operator.

Hi All,

Calculate the number of digits in the number using division operator.


Coding:

import java.io.*;
import java.util.*;
public class MyCode {
   public static void main(String args[] ) throws Exception {

Scanner scan  = new Scanner(System.in);
int num = scan.nextInt();
int count = 0;
    while(num !=0){
        num = num/10;
        count++;
    }
    System.out.println("Calculating the number of digits: "+ count);
   }
}

Output:

36251

Calculating the number of digits: 5

No comments:

Post a Comment

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...