I see some errors in your code.
Your probably meant the mathematical term
90 <= angle <= 180, meaning angle in range 90-180.
if (angle >= 90 && angle <= 180) {
// do action
}
Answer from AlexWien on Stack OverflowI see some errors in your code.
Your probably meant the mathematical term
90 <= angle <= 180, meaning angle in range 90-180.
if (angle >= 90 && angle <= 180) {
// do action
}
You can use apache Range API. https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/Range.html
Videos
I am making a math workout program and I need to prompt the user to input what digit range would he want in his math problem (using numbers from 0 to 9, from 10 to 100...).
I thought about making an int array (say I want addition problems that user numbers no bigger than 100 and no smaller than 0, id write int[] range = {0, 100}).
Then id use that array in generating numbers for the problem.
Is this the best way?
Apache Commons Lang has a Range class for doing arbitrary ranges.
Range<Integer> test = Range.between(1, 3);
System.out.println(test.contains(2));
System.out.println(test.contains(4));
Guava Range has similar API.
If you are just wanting to check if a number fits into a long value or an int value, you could try using it through BigDecimal. There are methods for longValueExact and intValueExact that throw exceptions if the value is too big for those precisions.
You could create a class to represent this
public class Range
{
private int low;
private int high;
public Range(int low, int high){
this.low = low;
this.high = high;
}
public boolean contains(int number){
return (number >= low && number <= high);
}
}
Sample usage:
Range range = new Range(0, 2147483647);
if (range.contains(foo)) {
//do something
}