-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCounter.java
48 lines (41 loc) · 1.1 KB
/
Counter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.yurii.salimov.lesson06.task01;
/**
* @author Yuriy Salimov ([email protected])
* @version 1.0
*/
public final class Counter extends Thread {
private final int rangeStart;
private final int rangeEnd;
public Counter(final int rangeStart, final int rangeEnd) {
if (rangeStart < rangeEnd) {
this.rangeStart = rangeStart;
this.rangeEnd = rangeEnd;
} else {
this.rangeStart = rangeEnd;
this.rangeEnd = rangeStart;
}
}
@Override
public void run() {
while (!isInterrupted()) {
for (int i = this.rangeStart; i <= this.rangeEnd; i++) {
System.out.print(i + " ");
}
System.out.println();
sleep();
}
}
public int getRangeStart() {
return this.rangeStart;
}
public int getRangeEnd() {
return this.rangeEnd;
}
private void sleep() {
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
System.out.println("Thread stop!");
}
}
}