-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainLesson4_1.java
More file actions
32 lines (23 loc) · 918 Bytes
/
MainLesson4_1.java
File metadata and controls
32 lines (23 loc) · 918 Bytes
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
package ru.MylearnCh1J1L1;
import java.util.LinkedList;
import java.util.Random;
public class MainLesson4_1 {
public static void main(String[] args) {
LinkedList<Integer> ll = new LinkedList<>();
randFillList(10, 100, ll);
LinkedList<Integer> newLL = returnReversedList(ll);
System.out.println(ll.toString());
System.out.println(newLL.toString());
}
public static LinkedList<Integer> returnReversedList(LinkedList<Integer> list) {
LinkedList<Integer> newList = new LinkedList<>();
for(int i = list.size(); i > 0; i--) newList.add(list.get(i - 1));
return newList;
}
public static void randFillList(int count, int maxValue, LinkedList<Integer> list) {
Random rand = new Random();
for (int i = 0; i < count; i++) {
list.add(rand.nextInt(maxValue));
}
}
}