-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay41_prob2.java
More file actions
87 lines (71 loc) · 2.24 KB
/
Day41_prob2.java
File metadata and controls
87 lines (71 loc) · 2.24 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
/*
During the discussion on Lambda Expressions, Dr. Wangdu told the students that Lambda Expressions can be passed as an argument to represent the Object of any Functional Interface.
He defined a functional interface Test with an abstract method int count(int [] arr) and asked his students to implement 2 Lambda expressions one to count all the prime numbers in an array and second to count all the even numbers of the array which are divisible by 5.
A class Demo is given with a method void count(Test ob) Help the students to complete the given code.
Input Format
First line reads the number of elements N in the array
Second line reads the N integers separated by SPACE
Constraints
N > 0 and N < 10
Output Format
Prints the number of PRIME NUMBERS in the array and COUNT of all the even numbers separated by SPACE
Sample Input 0
5
11 3 15 8 10
Sample Output 0
2 1
*/
// Kirtan Jain
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
interface Test
{
int count(int [] arr);
}
class Demo{
void count(Test ob, int [] arr){
System.out.print(ob.count(arr)+" ");
}
}
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a= new int[n];
for(int i=0;i<n;i++){
a[i]=sc.nextInt();
}
Demo ob1 = new Demo();
ob1.count(arr->{
int ans1=0;
for(int i=0;i<arr.length;i++){
int flag=0;
if(arr[i]==1){
continue;
}
for(int j=2;j<arr[i];j++){
if(arr[i]%j==0){
flag=1;
}
}
if(arr[i]!=0 && flag==0){
ans1++;
}
}
return ans1;
}, a);
ob1.count(arr->{
int ans2=0;
for(int i=0;i<arr.length;i++){
if(arr[i]!=0 && arr[i]%10==0){
ans2++;
}
}
return ans2;
}, a);
}
}