public class Piramide {
public static void print(LinkedList<Integer> list, int n) {
StringBuilder sb = new StringBuilder();
Iterator<Integer> it;
if (n == 0) {
it = list.descendingIterator();
} else {
it = list.iterator();
}
while (it.hasNext()) {
sb.append(it.next()).append("-");
}
sb.deleteCharAt(sb.length() - 1);
System.out.println(sb.toString());
}
public static void main(String[] args) {
int n = 6;
System.out.printf("n = %d\n", n);
LinkedList<Integer> list = new LinkedList<Integer>();
for (int i = 1; i <= n; i++) {
list.add(i);
print(list, i & 1);
}
}
}
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |