-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise5.java
32 lines (26 loc) · 1.09 KB
/
Exercise5.java
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
import java.util.Scanner;
public class Exercise5{
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
String string = scanner.nextLine();
listWords(string);
}
public static void listWords(String str){
String[] words = str.split("[\\s\\.?,!]");
for(int i=0; i<words.length-1; i++){
int count=1;
if(words[i].isEmpty()){
continue;
}
for(int j=i+1; j<words.length; j++){
if(words[i].equalsIgnoreCase(words[j])){
count++;
}
}
//neu in nhu the nay thi nhung tu xuat hien hon 3 lan va xuat hien cang o cuoi chuoi thi in se trung
if(count==2){
System.out.println(words[i]);
}
}
}
}