Regex matching an hyphen separated range [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 23 hours ago.
Improve this question
I have 2 different range expressions as follows:
1 - 10 cm
5+ m
and I'd like to extract min, max and unit from these expressions using Regex (where I am a newbie at), like:
Integer min = 1
Integer max = 10
String unit = "cm"
and
Integer min = 5
Integer max = null
String unit = "m"
respectively. Is it possible to do it using one pattern, if so how?
Thanks in advance...

Related

Permutations of array with at minimum 1 element [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 17 days ago.
Improve this question
I am trying to produce all permutations of an array of size N (i.e. N = 9) with possible elements Z (i.e. Z = [0,1,2,3,4])
Duplicates are allowed, but there needs to be at least one. I am able to write the algorithm to go through all possibilities but the minimum of at least one of each of Z is the part I'm having trouble with.
Looking to do this algorithm in java. Can someone help?

convert to lower of nearest 1000 in java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
convert to lower of nearest 1000 in java
I want to convert to lower 1000 example
4300 should be 4000
4900 should be 4000
10050 should be 10000
how can we do this using java
sorry for the bad english
int value = …
int nearestThousand = value / 1_000 * 1_000;

Regex to get the last value [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
From the following value
[AAMP-PLAYER]aamp pos: [14..187..202..2196879032]
I want to get the last number 2196879032
Some times value will be -1
[AAMP-PLAYER]aamp pos: [14..187..202..-1]
Instead of split method how can i extract last digit using regex method
You could match the last (possibly negative) number at the end of the string, just before the closing ]:
(\-?\d+)\]$
A number is last if it is not followed (following it anywhere, not just immediately) by any other number.
(\-?\d+)(?!.*\d)
We could try using a String#replaceAll option here:
String input = "[AAMP-PLAYER]aamp pos: [14..187..202..2196879032]";
String num = input.replaceAll("^.*\\.\\.(-?\\d+).*$", "$1");
System.out.println(num);
This prints:
2196879032

10 random words without repetition [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have 20 words in sql database in android
I want to choose 10 random words without repeating and put it in 10 textview if activity is starting
I find this code but it's for numbers only
ArrayList<Integer> number = new
ArrayList <Integer>();
for (int i = 1; i <= 10; ++i)
number.add(i);
Collections.shuffle(number);
If they are in a SQL database, you can use the query:
select word
from t
order by rand()
limit 10;
With 20 words, this should have quite reasonable performance. But if the number of words grows, performance could be an issue.
If you've got XQuery 3.1 you can do
random-number-generator()?permute($words)[position()=1 to 10]
Try this
SELECT TOP 20 WordField
FROM TableName
ORDER By rand()

How Convert packages to units [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a question, I'm programming in Java if I have a decimal "3.02" (this is equivalent to 3 packages (1 package = 10 units) and 2 units) and want to convert to "32" (this is equivalent to 32 units ). Does anyone know how to do it? There is a feature that allows java?
If 3 represent the units and the decimal part is 02 then your math is not coherent as it must, since you need 10 units to increment 1 package, I will expected that 3.2 represents 3 packages and 2 units
anyways a code snipped that can solve your math can be:
double totalToConvert = 3.02;
int totalAsInteger = (int) totalToConvert;
System.out.println(totalAsInteger);
int decimalPart = (int)((double)(totalToConvert-totalAsInteger)*100);
int total = totalAsInteger*10 +decimalPart;
System.out.println(total
);

Categories

Resources