Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java check how many digits in a number

int n = 1000;
int length = (int)(Math.log10(n)+1);

//NB: only valid for n > 0
Comment

number of digits java

  public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();

        int count = 0;

        while (num > 0) {
            num /= 10;
            count++;
        }
        System.out.println("number of digits: " + count);
    }
Comment

how to check the number of digits in a number in java

int length = (int) (Math.log10(number) + 1);
Comment

number of digits program in java

int numOfDigits = ((int) Math.floor(Math.log10(number))) + 1
Comment

PREVIOUS NEXT
Code Example
Java :: Get the last day of a month in Java 
Java :: switch case java with char 
Java :: java bean 
Java :: java arraylist deep copy 
Java :: Adding in java using user input 
Java :: Simple gui in java 
Java :: arrays.aslist 
Java :: java array initialization 
Java :: PathProviderPlugin.java uses unchecked or unsafe operations. 
Java :: java time difference 
Java :: jframe color 
Java :: java constructor chaining 
Java :: spring swagger 
Java :: java try and catch 
Java :: java how to compare strings 
Java :: java currency format 
Java :: dropdown menu with spinner dropdown icon color change in android 
Java :: switch case in android studio - java 
Java :: android iinput edit text password icon change 
Java :: arraylist replace value java 
Java :: how to add chips dynamically android 
Java :: How to draw Bezier Curve in Android 
Java :: what is packages in java 
Java :: java object to int 
Java :: android maven dependency 
Java :: how to get 2 decimal places in java 
Java :: while loop in java 
Java :: java first character string number 
Java :: how to run java files 
Java :: java to the power of 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =