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
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