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 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 :: log4j2.properties file need to save in spring boot application 
Java :: Exception in Application start method java.lang.reflect.InvocationTargetException 
Java :: extract substring in string java 
Java :: loop through array in java 
Java :: convert array to arraylist 
Java :: how to create a derived class in Java 
Java :: how to find a string in a sentence in java 
Java :: java swing tablecellrenderer 
Java :: int in string umwandeln 
Java :: rest api client url not connecting to the database in spring boot 
Java :: array srting line by line in textview android 
Java :: how to calculate min, max and average and write the output into into a text file in java 
Sql :: delete all data in neo4j 
Sql :: fatal error: libpq-fe.h: No such file or directory 
Sql :: mysql current running queries 
Sql :: port 5432 is already in use mac 
Sql :: drop stored procedure mysql 
Sql :: pl sql output 
Sql :: alter table add comment oracle 
Sql :: starts and end with vowel sql 
Sql :: show table columns mysql command line 
Sql :: pl sql escape & 
Sql :: get schema of table sql 
Sql :: sql last row in table 
Sql :: mysql text to decimal 
Sql :: mysql last day of next month 
Sql :: mysql random limit 1 
Sql :: oracle current date without time 
Sql :: netstat -tln mysql 
Sql :: psql lst trigger 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =