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
<code class="java">[start, end]</code>
For example:
<code class="java">[1, 10] // 包含 1 和 10</code>
2. Open interval
<code class="java">(start, end)</code>
For example:
<code class="java">(1, 10) // 包含 2-9,但不包含 1 和 10</code>
3. Half-open interval
<code class="java">[start, end)</code>
For example:
<code class="java">[1, 10) // 包含 1-9,但不包含 10</code>
<code class="java">(start, end]</code>
For example:
<code class="java">(1, 10] // 包含 2-10,但不包含 1</code>
4. Unbounded interval
<code class="java">(-∞, end)</code>
For example:
<code class="java">(-∞, 10) // 包含所有小于或等于 10 的整数</code>
<code class="java">(start, ∞)</code>
For example:
<code class="java">(5, ∞) // 包含所有大于或等于 5 的整数</code>
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!