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 Overflow
🌐
Educative
educative.io › answers › what-is-rangebetween-in-java
What is Range.between() in Java?
the methods in Java that can be called without creating an object of the class. method of the Range which is used to obtain an instance of Range with the specified minimum and maximum value.
🌐
Medium
medium.com › @AlexanderObregon › checking-if-a-number-is-within-a-range-in-java-da2729ea3e05
Checking if a Number Is Within a Range in Java | Medium
August 25, 2025 - Learn how Java checks if numbers fall within a range. Covers comparison operators, inclusive and exclusive limits, floating point rules, and edge cases.
🌐
Baeldung
baeldung.com › home › java › java numbers › how to check whether an integer exists in a range with java
How to Check Whether an Integer Exists in a Range with Java | Baeldung
January 18, 2024 - For example, suppose we wanted ... these two ranges: R1 = [10, 2o), a left-closed right-open range, and R2 = (10, 20], a left-open right-closed range. Since R1 does not contain its upper bound, the integer 20 exists only in R2.
🌐
Reddit
reddit.com › r/learnprogramming › what is the best way to store an integer range in java?
r/learnprogramming on Reddit: What is the best way to store an integer range in java?
August 22, 2017 -

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?

Top answer
1 of 2
5
Just store the min and max in separate int variables. That's the easiest approach. To generate the numbers to solve all you need to do is generate a random number in the range. Here, you can use the .nextInt() method from the Random class: Random rng = new Random(); // create a new Random generator instance int numberInRange = rng.nextInt((max + 1) - min) + min; The line int numberInRange = rng.nextInt((max + 1) - min) + min; generates a random number in the range min to max (inclusive). The parameter of the .nextInt() method is the maximum range excluded, so .nextInt(10) will generate random numbers in the range 0 to 9. By adding 1 to max I include max in the range, and then I subtract the min to get the range of possible numbers, that then need to be offset by adding min. As a concrete example: your range 10 to 100 inclusive Random rng = new Random(); // create a new Random generator instance int min = 10; int max = 100; int numberInRange = rng.nextInt((max + 1) - min) + min; When you calculate: max + 1, you get 101. Were you using this value as upper boundary for the .nextInt method, you'd get numbers in the range 0 to 100 inclusive. since you want 10 to 100 inclusive, you only have 91 distinct numbers, so you need to subtract the min (10) from the above result, 101 - 10 yields 91 Now, the .nextInt method produces numbers in the range 0 to 90 inclusive Last, by adding min to the random number generated above, you offset the range so that it goes from 10 to 100. Edit: optimally, you'd move the random number in range generation into its own method. My approach would be as follows: At class level (as a field): static Random rng = new Random(); The method itself: public static int rangedRandomInt(int min, int max) { return rng.nextInt((max + 1) - min) + min; } Or, with late initialisation At class level (as a field): static Random rng; The method itself: public static int rangedRandomInt(int min, int max) { if(rng == null) { // on-demand initialization of Random number generator rng = new Random(); } return rng.nextInt((max + 1) - min) + min; }
2 of 2
2
I agree with u/desrtfx . When you use an array (or some separate Range class) you’re creating a reference to a completely separate object, and one whose length is effectively unknown until the JRE starts optimizing. When you use two separate variables, their values are embedded directly in the body of their class or stack frame, and the compiler/JRE can see everything except the eventual run-time value beforehand. If you need to pass ranges around between methods or return them from a public method, you’ll either have to take two separate arguments as int min, int max or bite the bullet and come up with some class Range to bundle them up. You can also bundle two ints up into a long for internal passing-around, should the need arise: long bundle = (min & 0xFFFFFFFFL) | ((long)max << 32); int bundle_min = (int)bundle; int bundle_max = (int)(bundle >>> 32); In general—and Java makes this sort of hard in some places—it’s best to tie down your implementation as much as possible type-wise, so that neither you, nor users, nor other programmers can easily break things (e.g., by passing new int[0]). The types and variable names then serve as additional documentation, clarifying what the int values actually mean to the program.
🌐
Coderanch
coderanch.com › t › 481376 › java › write-statement-range-values
how to write: IF statement with range of values (e.g. if 5 > x > 10, then ... ) (Beginning Java forum at Coderanch)
February 3, 2010 - saddam mohammed wrote:. . . // This is correct range of x between 5 and 10 . . . That is probably not correct; please write which numbers will cause that test to evaluate to true.
🌐
Quora
quora.com › How-can-I-make-a-range-method-for-numbers-in-Java
How to make a range method for numbers in Java - Quora
Answer (1 of 6): Two steps: 1. Because these data have two features, the length and the value. You can make the length of data ,that is , length of 1 length of 2 length of 3 length of 4 . 2. of course the data of length of 4 is 1000. and then for length of 3 , 2 and 1. you can get the remainder ...
🌐
Baeldung
baeldung.com › home › java › java numbers › generating random numbers in a range in java
Generating Random Numbers in a Range in Java | Baeldung
May 11, 2024 - Generate Bounded and Unbounded Random Strings using plain Java and the Apache Commons Lang library. ... Math.random gives a random double value that is greater than or equal to 0.0 and less than 1.0. Let’s use the Math.random method to generate a random number in a given range [min, max):
Find elsewhere
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
Java Wrapper Classes Java Generics Java Annotations Java RegEx Java Threads Java Lambda Java Advanced Sorting ... How Tos Add Two Numbers Swap Two Variables Even or Odd Number Reverse a Number Positive or Negative Square Root Area of Rectangle Celsius to Fahrenheit Sum of Digits Check Armstrong Num Random Number Count Words Count Vowels in a String Remove Vowels Count Digits in a String Reverse a String Palindrome Check Check Anagram Convert String to Array Remove Whitespace Count Character Frequency Sum of Array Elements Find Array Average Sort an Array Find Smallest Element Find Largest Element Second Largest Array Min and Max Array Merge Two Arrays Remove Duplicates Find Duplicates Shuffle an Array Factorial of a Number Fibonacci Sequence Find GCD Check Prime Number ArrayList Loop HashMap Loop Loop Through an Enum
🌐
Baeldung
baeldung.com › home › java › java numbers › listing numbers within a range in java
Listing Numbers Within a Range in Java | Baeldung
January 8, 2024 - In this tutorial, we’ll explore different ways of listing sequences of numbers within a range.
🌐
Codecademy
codecademy.com › forum_questions › 53cf4ce4282ae3d166000fa7
How do i set it to "between" two numbers? | Codecademy
> 1) If computerChoice is between 0 and 0.33, make computerChoice equal to "rock". > 2) If computerChoice is between 0.34 and 0.66, make computerChoic...
🌐
LabEx
labex.io › tutorials › java-how-to-check-if-a-number-is-within-a-specific-range-in-java-559970
How to Check If a Number Is Within a Specific Range in Java | LabEx
Understanding how to work with ... a specific set of numbers. A range is simply a set of numbers between a starting point (the lower bound) and an ending point (the upper bound)....
🌐
YouTube
youtube.com › shorts › -ZZ9pTov08I
Get the Array of numbers between two numbers in Java. #shorts #javainterviewquestions - YouTube
Get the Array of numbers between two numbers in Java. #shorts #javainterviewquestions Schedule a meeting in case of any queries/guidance/counselling:https://...
Published   March 21, 2023
🌐
Alvin Alexander
alvinalexander.com › java › java-method-integer-is-between-a-range
A Java method to determine if an integer is between a range | alvinalexander.com
public static boolean between(int i, int minValueInclusive, int maxValueInclusive) { if (i >= minValueInclusive && i <= maxValueInclusive) return true; else return false; } If you want, you can make that code shorter with the Java ternary operator syntax (which I don’t like), or better yet, like this:
🌐
Java67
java67.com › 2018 › 01 › 3-ways-to-generate-random-integers-on.html
3 ways to create random numbers in a range in Java - Examples | Java67
If you want to know more about ThreadLocalRandom, I suggest you read The Definitive Guide to Java Performance by Scott Oaks, he has an excellent write-up on that topic. 4) The best way to generate random integers between a range is by using the RandomUtils class from Apache Commons Lang. This was added to a newer version of Apache commons-lang and returns an integer value between two given numbers.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-check-if-number-between-two-numbers
Check if a Number is Between Two Numbers in JavaScript | bobbyhadz
Once we have the lower and higher ranges, we can use an if statement to check if the number is less than the higher range and greater than the lower range. If both conditions are met, the number is between the two numbers.
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-basic-exercise-33.php
JavaScript basic: Check whether two numbers are in range 40..60 or in the range 70..100 inclusive - w3resource
June 30, 2025 - JavaScript exercises, practice and solution: Write a JavaScript program to check whether two numbers are in the range 40..60 or 70..100 inclusive.
🌐
Blogger
javarevisited.blogspot.com › 2013 › 05 › how-to-generate-random-numbers-in-java-between-range.html
How to Generate Random Numbers in Java Between Range - Example Tutorial
August 3, 2021 - This code uses Math.random() method, which returns pseudo-random number in a range 0.0 to 1.0, where later is exclusive, by multiplying output with and then type casting into int, we can generate random integers in any range. If you need pseudo random number between 1 to 100, you can simply ...
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › find-the-minimum-distance-between-two-numbers
Find the minimum distance between two numbers - GeeksforGeeks
July 23, 2025 - // Java Program to Find the minimum // distance between two numbers import java.io.*; class MinimumDistance { int minDist(int arr[], int n, int x, int y) { int i, j; int min_dist = Integer.MAX_VALUE; for (i = 0; i < n; i++) { for (j = i + 1; j < n; j++) { if ((x == arr[i] && y == arr[j] || y == arr[i] && x == arr[j]) && min_dist > Math.abs(i - j)) min_dist = Math.abs(i - j); } } if (min_dist > n) { return -1; } return min_dist; } public static void main(String[] args) { MinimumDistance min = new MinimumDistance(); int arr[] = { 3, 5, 4, 2, 6, 5, 6, 6, 5, 4, 8, 3 }; int n = arr.length; int x = 0; int y = 6; System.out.println("Minimum distance between " + x + " and " + y + " is " + min.minDist(arr, n, x, y)); } } Python3 ·