-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.java
More file actions
89 lines (78 loc) · 2.14 KB
/
Copy pathProgram.java
File metadata and controls
89 lines (78 loc) · 2.14 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package lab1;
import java.util.*;
public class Program extends Solution {
public static void main(String[] args)
{
Deque<Float> vec = new LinkedList<>();
Scanner sc = new Scanner(System.in);
p("Введите количество элементов");
int n = sc.nextInt();
for (int i=0; i<n; i++)
{
p("Введите элемент " + (i+1));
vec.offer(sc.nextFloat());
}
print(vec, 0);
avg(vec,n);
print(vec, 1);
int key = gotKey();
delKey(vec, key);
print(vec, 2);
refresh(vec);
print(vec,3);
}
public static Deque<Float> refresh(Deque<Float> arr)
{
float min = Collections.min(arr);
p("Minimum is "+min);
ArrayList<Float> list = arrayIt(arr);
for (int i=0; i<list.size(); i++)
{
arr.offerLast(list.get(i)-min);
}
return arr;
}
public static void print(Deque<Float> arr, int x)
{
p("Task "+x);
Iterator<Float> it = arr.iterator();
while (it.hasNext()) {
Float s = it.next();
p(s);
}
}
public static void p(Object o)
{
System.out.println(o.toString());
}
public static Deque<Float> avg(Deque<Float> arr, int n)
{
float sum = 0;
Iterator<Float> it = arr.iterator();
while (it.hasNext()) {
sum+= it.next();
}
arr.push(sum/n);
return arr;
}
public static ArrayList<Float> arrayIt(Deque<Float> arr)
{
ArrayList<Float> list = new ArrayList<>();
Iterator<Float> it = arr.iterator();
while (it.hasNext()) {
list.add(it.next());
it.remove();
}
return list;
}
public static Deque<Float> delKey(Deque<Float> arr, int n)
{
ArrayList<Float> list = arrayIt(arr);
list.remove(n);
for (int i=0; i<list.size(); i++)
{
arr.offerLast(list.get(i));
}
return arr;
}
}