Skip to content

Commit 04983cc

Browse files
Pavel MakarovPavel Makarov
Pavel Makarov
authored and
Pavel Makarov
committed
add new class
1 parent 81d58e3 commit 04983cc

23 files changed

+70
-3
lines changed

2_Iterator.java

100755100644
+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public static void main(String[] args) {
3737
System.out.println(iterator.value());
3838
}
3939

40-
for ( ; !iterator.over(); iterator.prev() ) {
41-
System.out.println(iterator.value());
42-
}
40+
// for ( ; !iterator.over(); iterator.prev() ) {
41+
// System.out.println(iterator.value());
42+
// }
4343
}
4444
}
File renamed without changes.
File renamed without changes.

Iterator.class

1005 Bytes
Binary file not shown.

Iterator.java

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
public class Iterator {
2+
private int first;
3+
private int step;
4+
private int index;
5+
6+
public Iterator(int first, int step, int index) {
7+
this.first = first;
8+
this.step = step;
9+
this.index = index;
10+
}
11+
public void next() {
12+
if ( over() ) {
13+
return;
14+
}
15+
first += step;
16+
index -= 1;
17+
}
18+
public void prev() {
19+
if ( over() ) {
20+
return;
21+
}
22+
first -= step;
23+
index -= 1;
24+
}
25+
public boolean over() {
26+
return index == 0;
27+
}
28+
public int value() {
29+
return first;
30+
}
31+
32+
33+
public static void main(String[] args) {
34+
Iterator iterator = new Iterator(10, 2, 4);
35+
36+
for ( ; !iterator.over(); iterator.next() ) {
37+
System.out.println(iterator.value());
38+
}
39+
40+
for ( ; !iterator.over(); iterator.prev() ) {
41+
System.out.println(iterator.value());
42+
}
43+
}
44+
}

Iterator_.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
public class Iterator_ {
2+
private int first;
3+
private int step;
4+
private int index;
5+
6+
public Iterator_(int first, int step, int index);
7+
public void next();
8+
public void prev();
9+
public boolean over();
10+
public int value();
11+
12+
public static void main(String[] args) {
13+
Iterator_ iterator = new Iterator_(10, 2, 4);
14+
15+
for ( ; !iterator.over(); iterator.next() ) {
16+
System.out.println(iterator.value());
17+
}
18+
19+
for ( ; !iterator.over(); iterator.prev() ) {
20+
System.out.println(iterator.value());
21+
}
22+
}
23+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)