Home > Java > javaTutorial > How to express range in java

How to express range in java

下次还敢
Release: 2024-04-25 23:00:33
Original
1124 people have browsed it

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.

How to express range in java

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]
Copy after login

For example:

[1, 10] // 包含 1 和 10
Copy after login

2. Open interval

(start, end)
Copy after login

For example:

(1, 10) // 包含 2-9,但不包含 1 和 10
Copy after login

3. Half-open interval

[start, end)
Copy after login

For example:

[1, 10) // 包含 1-9,但不包含 10
Copy after login
(start, end]
Copy after login

For example:

(1, 10] // 包含 2-10,但不包含 1
Copy after login

4. Unbounded interval

(-∞, end)
Copy after login

For example:

(-∞, 10) // 包含所有小于或等于 10 的整数
Copy after login
(start, ∞)
Copy after login

For example:

(5, ∞) // 包含所有大于或等于 5 的整数
Copy after login

Notes

  • The starting point and end of the interval Points must be integers.
  • Intervals cannot overlap.
  • Unbounded intervals represent infinite ranges, and can be used to represent concepts such as all integers or all positive integers.

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template