-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
39 lines (30 loc) · 788 Bytes
/
test.java
File metadata and controls
39 lines (30 loc) · 788 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
33
34
35
36
37
38
39
import java.util.ArrayList;
public class test {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(-2);
list.add(3);
list.add(5);
list.add(0);
ArrayList<Integer> asn = new ArrayList<>();
asn = remove(list);
for(int i : asn){
System.out.print(asn.get(i) + " ");
}
}
static public ArrayList<Integer> remove(ArrayList<Integer> list){
ArrayList<Integer> ans = new ArrayList<>();
for(int i : list){
if(i >0){
ans.add(1);
}else if(i < 0){
ans.add(i * i);
}else{
break;
}
}
return ans;
}
}