Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- final BigInteger limit = BigInteger.valueOf(317);
- Function<BigInteger, BigInteger> next = new Function<BigInteger, BigInteger>() {
- @Override public BigInteger apply(BigInteger val) {
- return val.add(BigInteger.ONE);
- }
- };
- Predicate<BigInteger> to = new Predicate<BigInteger>() {
- @Override public boolean apply(BigInteger val) {
- return limit.compareTo(val) >= 0;
- }
- };
- Iterable<BigInteger> nrs = range(BigInteger.valueOf(311), to, next);
- System.out.println(nrs); // use without loop
- for (BigInteger b : nrs) // use with for each loop
- System.out.println(b);
- /* Expected output:
- [311, 312, 313, 314, 315, 316, 317]
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement