check number between two numbers Android - android

How can i check if a number is between two other numbers in Android
if(number1.matches("[1024-65535]+"));
else{

One way to solve your problem is to convert all values that need to be compared into ints. Then the comparison is trivial.

Related

What to use for large numbers with precision?

I need a way to store large numbers with precision. Let's say I want to have 1'234'567'890.123456 in a variable. I was thinking about using Strings ( though it's not recommended ) but I believe there must be a much better way to do this.
BigDecimal gives you numbers with arbitrary precision. It is serialisable so you could save it like that, or use toString() and save that representation.
Take a look at BigDecimal. They are Immutable, arbitrary-precision signed decimal numbers.

Android app calculate until 2^28

Hello everyone i'm trying to figure up why does my calculate app cannot work with numbers bigger then 2^28.
The next num after the biggest is the smallest. Now I understand that the problem is with the definition of my variables but its an integer and at c++ integer variables are 8 bits numbrer that allows me to calculate 2^32.. so how do I get ridd of this bug?
Hey I solved the problem. If you want to do an app that calculates extreme numbers change the variables you use to "double" variable that can calc numbers until 2^64

Android - Do I need to sort a collection for min and max?

I came here (SO) a few days ago to research how to get the min and max from a collection in Android and found a solution to the effect of the following (sorry haven't got a link to the actual answer I used):
Max = (TextView)findViewById(R.id.Max);
Collections.sort(list);
Max.setText(String.format("%.2f", Collections.max(list)));
My question is do I actually need to sort the list before pulling the min/max value? I have tried running the code without sorting the list and it seems to work OK. I am just worried because the answer I used definitely sorted the list first so I assume there must be a reason, I just don't know what it is!
In addition #BobbyDigital's answer who corectly points out the th method iterates over the complete list, I would just like to mention that the result of using the max function might depend on the type of the list elements. If you see the doc , it says that
Returns the maximum element of the given collection, according to the natural ordering of its elements.
If you see Why does Collections.max() not return actual max value for a Collection of String? question, the person used a list of Strings. On extracting max using the abve number he did not get the max number as it was returning the value that's the largest lexicographically. So, just to mention his code:
ArrayList<String> dirNo = new ArrayList<String>();
dirNo.add("1");
dirNo.add("2");
dirNo.add("3");
dirNo.add("4");
dirNo.add("5");
dirNo.add("6");
dirNo.add("7");
dirNo.add("8");
dirNo.add("9");
dirNo.add("10");
dirNo.add("11");
System.out.println("max : " + Integer.parseInt(Collections.max(dirNo))
+ "");
The above code gave 9 as the answer. So be careful while using it. You mgiht want to convert everything to Integer etc based on your needs.
P.S: The example is from the question mentioned and the answer is inspired from this answer by NPE on same question.
No it doesn't have to be sorted. The method iterates over the entire collection.
See the Java docs for the method!

Partial comparison of 2 strings

I'm looking for a way to compare 2 strings partial. I need to clear this with an example.
The base string is "equality".
The string I need to check is spelled wrong: "equallaty". I want to conform this is partially correct so the input, even not right in a grammar way, is the same as the base string.
Now I can of course parse the string to an char array. Now I can check every single character, but if I check the first 4 characters they will be right, the rest will be wrong even if there are only 2 mistakes. So the check I want to use is that a minimum of 70 procent of the characters should match.
Is anyone able to help me get on the right track?
Compare the strings with an edit-distance metric like the Levenshtein distance. Such a metric basically counts the number of changes needed to make the strings equal. If the number of changes is small relative to the total size of the string, then you can consider the strings similar.

How to add two 40 digit numbers in Objective-C and Android

I want to know how to add two 40 digit numbers both in Objective C and Android.
Example:
4000000000000000000000000000000000000000000000000000000000
+5000000000000000000000000000000000000000000000000000000000
How to store and where to store these values?
What is the solution for this?
In Android you can use the BigInteger class for arbitrary sized integers. As for storing them, depends on what you need to store them for, but android has a number of storage options described here that should be able to store these large integers.
in case of objective-c, following code is been used to do the calculation
NSDecimalNumber *aNumber = [NSDecimalNumber decimalNumberWithString:#"4000000000000000000000000000000000000000"];
NSDecimalNumber *bNumber = [NSDecimalNumber decimalNumberWithString:#"2000000000000000000000000000000000000000"];
NSDecimalNumber *cNumber = [aNumber decimalNumberByAdding:bNumber];
NSLog(#"%#", cNumber);
here we use the NSDecimalNumber.

Categories

Resources