mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-09 20:20:56 +08:00
Merge pull request #1369 from Utsav1999/utsav-math
Added Count Digit program
This commit is contained in:
20
Maths/CountDigit.java
Normal file
20
Maths/CountDigit.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import java.util.*;
|
||||||
|
package Maths;
|
||||||
|
// count the number of digits in a number
|
||||||
|
class CountDigit {
|
||||||
|
public static void main(String args[]) {
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
System.out.print("Enter the number: ");
|
||||||
|
int number = sc.nextInt();
|
||||||
|
int digits = 0;
|
||||||
|
if(number == 0)
|
||||||
|
{
|
||||||
|
System.out.println("The number of digits present in the number: 1");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
digits = (int)Math.floor(Math.log10(Math.abs(number)) + 1);
|
||||||
|
System.out.println("The number of digits present in the number: " + digits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user