-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollectComments.java
More file actions
44 lines (35 loc) · 1.34 KB
/
CollectComments.java
File metadata and controls
44 lines (35 loc) · 1.34 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
import java.util.Scanner;
import java.util.ArrayList;
class CollectComments {
public ArrayList<String> collectComments(ArrayList<String> reviews){
ArrayList<String> result= new ArrayList<>();
for(int i=0;i<reviews.size();i++){
String new_comment= reviews.get(i);
if(new_comment.contains("!")){
String formatted_String= i+"."+new_comment;
if(!new_comment.endsWith("!") && !new_comment.endsWith(".")){
formatted_String += ".";
}
result.add(formatted_String);
}
}
return result;
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
CollectComments obj= new CollectComments();
System.out.println("Enter the number of elemnts in ArrayList");
int n = sc.nextInt();
sc.nextLine();
ArrayList<String> reviews= new ArrayList<>();
for(int i=0;i<n;i++){
System.out.println("Enter the comment number "+ (i+1) + " :-");
String comment= sc.nextLine();
reviews.add(comment);
}
ArrayList<String> result= obj.collectComments(reviews);
for(String num : result){
System.out.println(num);
}
}
}