-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay44_prob1.java
More file actions
72 lines (56 loc) · 1.66 KB
/
Day44_prob1.java
File metadata and controls
72 lines (56 loc) · 1.66 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
/*
Create a functional interface Predicate with an abstract method test with following signature: boolean test(String t); Write a test program to filter all the strings present in group of strings which ended with character ‘g’ by using above test method with the help of lambda expression.
Input Format
Your program should take 2 types of inputs. First will represents the number of Strings and second will be the objects of Strings. If the number of strings will be less than equal 1 then display the message “Invalid” without asking for any input.
Constraints
Number of strings should be greater than 1
Output Format
Should be list of the strings in separate lines which are ended with character ‘g’
Sample Input 0
5
Gang
Spring
Java
Live
Swing
Sample Output 0
Gang
Spring
Swing
Sample Input 1
1
Sample Output 1
Invalid
*/
// Kirtan Jain
import java.io.*;
import java.util.*;
interface Predicate {
boolean test(String t);
}
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();
if(n<2){
System.out.println("Invalid");
return;
}
Predicate obj=(st)->{
if(st.charAt(st.length()-1)=='g'){
return true;
}
else{
return false;
}
};
sc.nextLine();
for(int i=0;i<n;i++){
String s=sc.nextLine();
if(obj.test(s)){
System.out.println(s);
}
}
}
}