Advertisement
Guest User

Margus example

a guest
Dec 11th, 2010
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1.     public static void main(String[] args) {
  2.         final BigInteger limit = BigInteger.valueOf(317);
  3.         Function<BigInteger, BigInteger> next = new Function<BigInteger, BigInteger>() {
  4.             @Override public BigInteger apply(BigInteger val) {
  5.                 return val.add(BigInteger.ONE);
  6.             }
  7.         };
  8.         Predicate<BigInteger> to = new Predicate<BigInteger>() {
  9.             @Override public boolean apply(BigInteger val) {
  10.                 return limit.compareTo(val) >= 0;
  11.             }
  12.         };
  13.         Iterable<BigInteger> nrs = range(BigInteger.valueOf(311), to, next);
  14.  
  15.         System.out.println(nrs); // use without loop
  16.         for (BigInteger b : nrs) // use with for each loop
  17.             System.out.println(b);
  18.        
  19.         /*  Expected output:
  20.         [311, 312, 313, 314, 315, 316, 317]
  21.          311
  22.          312
  23.          313
  24.          314
  25.          315
  26.          316
  27.          317
  28.         */
  29.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement