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

how to find numbers of digits in 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 find some of digits in java

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

        int sum = 0;

        while (num > 0) {
            sum += num % 10;
            num /= 10;
        }
        System.out.println("sum of digits: " + sum);
    }
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 clone matrix 
Java :: initialize applet in java 
Java :: java set foreach 
Java :: pointers in java 
Java :: java string not equal 
Java :: can interface have attributes java 
Java :: java coalesce 
Java :: immutable map java 
Java :: armstrong number in java 
Java :: int [] to Integer[] 
Java :: brew use java 11 
Java :: how to change the value of an arraylist in java 
Java :: android sha1 key 
Java :: big java 2010 heaptree java program 
Java :: heap in java 
Java :: retrofit post header 
Java :: inheritance in oop 
Java :: declaration of list in java 
Java :: java sql query with parameters 
Java :: HUFFMAN CODING IN JAVA 
Java :: java program using FileOutputStream to create a file on mac 
Java :: character types java 
Java :: char to ascii java 
Java :: array of number arrays java 
Java :: richest customer wealth leetcode 
Java :: fixed length array powershell PSv5+ 
Java :: continue in java 
Java :: com.android.okhttp.internal.http.HttpURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection 
Java :: enum values to string array 
Java :: list.of java 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =