-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvenMoreList.java
More file actions
64 lines (58 loc) · 1.68 KB
/
Copy pathEvenMoreList.java
File metadata and controls
64 lines (58 loc) · 1.68 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.ArrayList;
public class EvenMoreList {
public ArrayList<Double> random(int n, int x){
ArrayList<Double> ans = new ArrayList<Double>();
double ran;
for (int i = 1; i <= n; i++){
ran = Math.random();
if (ran <= 0.5){
ans.add(Math.random() * x * -1);
}
else{
ans.add(Math.random() * x);
}
}
return ans;
}
public void posNeg(ArrayList<Integer> n){
ArrayList<Integer> pos = new ArrayList<Integer>();
ArrayList<Integer> neg = new ArrayList<Integer>();
for (int i = 0; i <= n.size() - 1; i++){
if (n.get(i) < 0){
neg.add(n.get(i));
}
if (n.get(i) >= 0){
pos.add(n.get(i));
}
}
System.out.println(pos);
System.out.println(neg);
}
public void reverse(ArrayList<Double> n){
double temp = 0;
for (int i = 0; i <= (n.size() - 1) / 2; i++){
temp = n.get(i);
n.set(i, n.get(n.size() - i - 1));
n.set(n.size() - i - 1, temp);
}
}
public static void main(String[]args){
EvenMoreList runner = new EvenMoreList();
System.out.println(runner.random(5, 10));
ArrayList<Integer> a = new ArrayList<Integer>();
a.add(-9);
a.add(3);
a.add(42);
a.add(-17);
a.add(-19);
runner.posNeg(a);
ArrayList<Double> b = new ArrayList<Double>();
b.add(1.0);
b.add(2.0);
b.add(3.0);
b.add(4.0);
b.add(5.0);
runner.reverse(b);
System.out.println(b);
}
}