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

numbers 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 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 :: android studio alert dialog box 
Java :: spring scheduled 
Java :: how to close a jframe in netbeans 
Java :: java subscript numbers 
Java :: android separator line in view 
Java :: timestamp with zone java 
Java :: array sort java 
Java :: java replace a character at end of string 
Java :: open website from android activity 
Java :: spring boot jackson infinite recursion 
Java :: get minimum of array java 
Java :: scanner.hasnext() 
Java :: integer.tostring java 
Java :: how to find the size of a queue in java 
Java :: check if list includes value java 
Java :: pointers in java 
Java :: android studio download 
Java :: setbackground java 
Java :: java how to define a function 
Java :: java loop using input user 
Java :: java 2d array length 
Java :: java look and feel system 
Java :: raise error java 
Java :: declaration of list in java 
Java :: convert a int to string in java 
Java :: calculate smallest angle difference 
Java :: how to use while loop in java 
Java :: first character string number java 
Java :: java get jar execution directory 
Java :: spring boot onetomany relationsion 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =