-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDuplicateWords.java
More file actions
53 lines (52 loc) · 910 Bytes
/
DuplicateWords.java
File metadata and controls
53 lines (52 loc) · 910 Bytes
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
package practicetime;
import java.util.*;
public class DuplicateWords
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String s1="";
String ss2="";
String s;
String ss[]=new String[100];
sc.nextLine();
for(int y=0;y<n;y++)
{
s=sc.nextLine();
//s=s.toLowerCase();
int j=0;
for(int i=0;i<s.length();i++)
{
if(s.charAt(i)!=' ')
{
s1=s1+s.charAt(i);
}
if(s.charAt(i)==' ' || i==(s.length()-1))
{
ss[j]=s1;
j++;
//System.out.println(" aa - "+s1);
s1="";
}
}
for(int i=0;i<j;i++)
{
if(i==0)
{
ss2=ss2+ss[i]+" ";
}
if(i>0 && (ss[i].equalsIgnoreCase(ss[i-1])==false))
{
ss2=ss2+ss[i]+" ";
}
else
{
continue;
}
}
System.out.println(ss2);
ss2="";
}
}
}