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 date with T 
Java :: convert java to kotlin online editor 
Java :: create a toast message in android 
Java :: specify decimal places java 
Java :: instantiate matrix java 
Java :: spring boot sql logging 
Java :: replace all punctuation in string java 
Java :: java int to double 
Java :: java create file and parent directories 
Java :: get random word from array java 
Java :: how to make an int into a string java 
Java :: how to open an activity from a fragment 
Java :: Char in scanner 
Java :: java decimalformat 
Java :: java create arraylist 
Java :: WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable 
Java :: java random unique number 
Java :: java linkedlist print 
Java :: android date time 
Java :: android BottomSheetDialogFragment not opening fully on landscape 
Java :: java iterate over list 
Java :: random java 
Java :: how to declare an array in java 
Java :: java array to string 
Java :: java image draw 
Java :: java arraylist print 
Java :: literals in java 
Java :: java singleton implementation 
Java :: java does file exist 
Java :: iterable interface in java 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =