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 :: java nested loop 
Java :: joining an array of strings in java 
Java :: last char in string java 
Java :: Array list deep copy 
Java :: isnull java 
Java :: viewpager androidx dependencies 
Java :: java switch case 
Java :: arraylist syntax in java 
Java :: how to remove null values in java 
Java :: java create unmodifiable list 
Java :: hashmap to list java 
Java :: how to get current date in java 
Java :: spring maven plugin 
Java :: sort list java 8 
Java :: how to update java on windows 10 
Java :: test a javafx project 
Java :: threads array java 
Java :: java write in a file without overwriting 
Java :: set textView.android:drawableEnd programmatically 
Java :: java protected private public 
Java :: nested list java 
Java :: setupactionbarwithnavcontroller problem 
Java :: throw error java 
Java :: sc.nextline skips 
Java :: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver 
Java :: install java using cmd 
Java :: kubectl config kubernetes dashboard 
Java :: check if first character of a string is a number java 
Java :: first and last digit of a number in java 
Java :: map in java 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =