-
Notifications
You must be signed in to change notification settings - Fork 161
/
java.program1
86 lines (74 loc) · 2.37 KB
/
java.program1
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
import java.util.*;
class project1_program
{
public static void main()
{
Scanner in=new Scanner(System.in);
String s="",s2="";
int len=0,i,len2=0,j,l=0;
char ch;
//INPUT A SENTENCE
System.out.println("ENTER A SENTENCE NOT MORE THAN 100 CHARACTERS");
s=in.nextLine();
s=s+" ";
s=s.toUpperCase();
len=s.length();//LENGTH OF THE INPUT
for(i=0;i<len;i++)
{
ch=s.charAt(i); //Extracting letters
if(ch!=' ')
s2=s2+ch;
else
{
len2=s2.length();
String a,b,d,wrd="";
int len3,c,p=0,g=0;
for(j=0;j<len2;j++)
{
a=s2.substring(j,j+1);
b=a;
c=0;
p=j+1;
for(int m=j+1;m<=len2;m++)
{
for( l=1;l>0;l++)
{
if(p<=(len2-1))
d=s2.substring(p,p+1);
else
d=s2.substring(p-1);
len3=b.length();
for(int q=0;q<len3;q++)
{
if(b.substring(q,q+1).equals(d))
{
c=1;
break;
}
}
if(c!=1)
{
b=b+d;
p++;
}//ADDITION OF CHARACTER IF NOT REPEATED
else
break;
}
if(c==1)
break;
//EXTRACTION OF THE SUBSTRING
}
if(l>=g)
{
g=l;
wrd=b;
}
b="";
}
// printing of the words
System.out.println(s2+"\t"+wrd);
s2="";b="";wrd="";
}
}
}
}