The range in Java represents a set of continuous integers, which can be expressed in the following ways: closed interval [start, end], including start and end; open interval (start, end), excluding start and end; semi-open interval [start, end) or (start, end], respectively excludes or includes end; unbounded interval (-∞, end) or (start, ∞), represents all integers less than or greater than the value.
Representation of range in Java
In Java, a range is represented as a set of consecutive integers. It can be represented in the following way:
1. Closed interval
[start, end]
For example:
[1, 10] // 包含 1 和 10
2. Open interval
(start, end)
For example:
(1, 10) // 包含 2-9,但不包含 1 和 10
3. Half-open interval
[start, end)
For example:
[1, 10) // 包含 1-9,但不包含 10
(start, end]
For example:
(1, 10] // 包含 2-10,但不包含 1
4. Unbounded interval
(-∞, end)
For example:
(-∞, 10) // 包含所有小于或等于 10 的整数
(start, ∞)
For example:
(5, ∞) // 包含所有大于或等于 5 的整数
Notes
The above is the detailed content of How to express range in java. For more information, please follow other related articles on the PHP Chinese website!