Linked Questions
32 questions linked to/from Way to get number of digits in an int?
14 votes
3 answers
97k views
Fastest way to get number of digits on a number? [duplicate]
I have do detect the amount of digits on a number. For example, 329586 has 6 digits. What I done, is simply parsing the number to string, and getting the string length, like: number.toString()....
7 votes
4 answers
53k views
How to count the number of digits in an int value? [duplicate]
Given the following code. int[] eg = {21,20,1,12,2} public numbers(int[] eg) { for(int i=0; i < eg.length; i++) I would expect eg.length to be 5, where eg[0] would = 21 eg[1] would = 20, ...
-1 votes
3 answers
12k views
Is there a way to find the length of a variable in Java? [duplicate]
long AccountNumber = 1234567890; public void setAccNum(long Number) try(the size of the account number is lesser than equal to 10){ this.Accountnumber = Number; } catch(Exception e)...
2 votes
3 answers
4k views
How to check if a three digit number is a palindrome? [duplicate]
I am creating a little trivial palindrome quiz in Java. I should at some point check if the user will enter more or less than a three digit number such as "1011" or "10" and display an error ...
0 votes
1 answer
639 views
Number of digits in the number without using String API [duplicate]
I have a requirement where i need to find the number of digits in a integer. I have searched it and got some tricks. But i also developed a my own trick. I just want to know if it is correct way to ...
-1 votes
4 answers
158 views
Digit amount in an integer [duplicate]
How can I find the amount of digits in an integer? Mathematically, and by using functions if there are any. I don't really know how to do that, since I'm a somewhat beginner.
4 votes
5 answers
254 views
How can I allocate memory for an array of digits (int) of a number with the length being equal to the number of digits of that number?
e.g. for int n = 1234 I could create a string (s.valueOf(n)), then I would define the array like this: int[] array = new int[s.length()]; //this allocates memory for an array with 4 elements Is ...
5 votes
4 answers
683 views
How can I optimize this class that solves this math sequence
Given an infinite sequence like so (commas inserted to make pattern more apparent): 1, 1 2, 1 2 3, 1 2 3 4, 1 2 3 4 5, 1 2 3 4 5 6 ,1 2 3 4 5 6 7, 1 2 3 4 5 6 7 8, 1 2 3 4 5 6 7 8 9, 1 2 3 4 5 6 7 8 ...
5 votes
6 answers
1k views
Optimal and efficient solution for the heavy number calculation?
I need to find the number of heavy integers between two integers A and B, where A <= B at all times. An integer is considered heavy whenever the average of it's digit is larger than 7. For example:...
1 vote
5 answers
2k views
Luhn checksum validation in Java
I have to replicate the luhn algorithm in Java, the problem I face is how to implement this in an efficient and elegant way (not a requirement but that is what I want). The luhn-algorithm works like ...
0 votes
4 answers
2k views
Dynamic Array Size in C++
I am looking for a way to dynamically set the size of an integer array depending on the passed parameter. For example this in pseudocode: int MyFunction(int number) { int myarr[amount of digits in ...
0 votes
5 answers
5k views
How to check for odd number of digits in Java?
I need to write a program that accepts the following conditions: It has to be an odd number, Have an odd number of digits, All of its digits have to be odd numbers and The number has to be between ...
0 votes
3 answers
4k views
What would be the SQL query/command to find length of numeric field from a table?
I want to know how we can find of length of Numeric field in sql. What will be the command / Query so that we can find length of perticular field in table. E.g.: For below table: Column1 Column2 1 ...
1 vote
4 answers
626 views
How to get count of numbers in int and how to split a number without making a string
I have a number like 601511616 If all number's length is multiple of 3, how can a split the number into an array without making a string Also, how can I count numbers in the int without making a ...
-2 votes
7 answers
665 views
How to calculate the no. of digits of a number in java? [closed]
Is there any single line of code that can be used to calculate the number of digits in a program? I mean to say, can be there a reference to a class (such as String.length for a String) which can be ...