14.3.1.1. Runnable.
Solution.
class PrintOdds implements Runnable {
private int bound;
public PrintOdds(int b) {
bound = b;
}
public void print() {
for (int k = 1; k <= bound; k += 2)
System.out.println(k);
}
public void run() {
print();
}
}
class PrintEvens implements Runnable {
private int bound;
public PrintEvens(int b) {
bound = b;
}
public void print() {
for (int k = 0; k <= bound; k += 2)
System.out.println(k);
}
public void run() {
print();
}
}