Difference between revisions of "Iterable Range Assignment"
Jump to navigation
Jump to search
(→Test) |
(→Client) |
||
Line 25: | Line 25: | ||
=Client= | =Client= | ||
− | {{Example| | + | {{Example|RangeClient|range.client}} |
The code: | The code: | ||
− | <nowiki>for (int i : | + | <nowiki>for (int i : Iterables.range(4, 12)) { |
System.out.println(i); | System.out.println(i); | ||
} | } | ||
System.out.println(); | System.out.println(); | ||
− | for (double d : | + | for (double d : Iterables.range(3.0, 7.1, 0.25)) { |
System.out.println(d); | System.out.println(d); | ||
}</nowiki> | }</nowiki> |
Revision as of 03:24, 26 November 2022
Contents
Java
interface java.lang.Iterable<T>
interface java.util.Iterator<T>
Code To Implement
class: | Ranges.java | |
methods: | minToMaxExclusive minToMaxExclusive minToMaxExclusive minToMaxExclusive |
|
package: | range.warmup | |
source folder: | src/main/java |
Integers
minToMaxExclusive(min, maxExclusive)
minToMaxExclusive(min, maxExclusive, step)
Doubles
minToMaxExclusive(min, maxExclusive)
minToMaxExclusive(min, maxExclusive, step)
Client
class: | RangeClient.java | |
package: | range.client | |
source folder: | src/main/java |
The code:
for (int i : Iterables.range(4, 12)) { System.out.println(i); } System.out.println(); for (double d : Iterables.range(3.0, 7.1, 0.25)) { System.out.println(d); }
produces the output:
4 5 6 7 8 9 10 11 3.0 3.25 3.5 3.75 4.0 4.25 4.5 4.75 5.0 5.25 5.5 5.75 6.0 6.25 6.5 6.75 7.0
Test
class: | IterableRangesTestSuite.java | |
package: | range.warmup | |
source folder: | src/test/java |