-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab13.java
More file actions
54 lines (51 loc) · 1.41 KB
/
Copy pathlab13.java
File metadata and controls
54 lines (51 loc) · 1.41 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
public class lab13
{
// ArrayList<Integer> field that is accessible to all my classes
private java.util.ArrayList<Integer> ints = new java.util.ArrayList<Integer>();
public void readData(String Filename)
{
try
{
java.io.BufferedReader input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream(Filename)));
String inn;
while( (inn = input.readLine()) != null )
{
ints.add(Integer.valueOf(inn.trim()));
}
input.close();
}
catch(Exception e)
{
System.out.println(e.toString());
System.exit(0);
}
}
public long getTotalCount()
{
return ints.stream().count();
}
public long getOddCount()
{
return ints.stream().filter(ints -> ints % 2 == 1).count();
}
public long getEvenCount()
{
return ints.stream().filter(ints -> ints % 2 == 0).count();
}
public long getDistinctGreaterThanFiveCount()
{
return ints.stream().filter(ints -> ints > 5).distinct().count();
}
public Integer[] getResult1()
{
return ints.stream().filter(ints -> ints % 2 == 0).filter(ints -> ints > 5).filter(ints -> ints < 50).sorted().toArray(Integer[]::new);
}
public Integer[] getResult2()
{
return ints.stream().map(ints -> ints * ints).map(ints -> ints * 3).limit(50).toArray(Integer[]::new);
}
public Integer[] getResult3()
{
return ints.stream().filter(ints -> ints % 2 == 1).map(ints -> ints * 2).sorted().skip(20).distinct().toArray(Integer[]::new);
}
}