0% found this document useful (0 votes)
16 views6 pages

Aaditicomputerproject

Uploaded by

AJP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

Aaditicomputerproject

Uploaded by

AJP
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

import.java.util.

*;
class LongestSubstring
{
public static boolean isRepeated(String w)
{
int i,j,len;
char ch1,ch2;
boolean result=false;
w=w.toUpperCase();
len=w.length();
if(w>100)
{
break;
System.out.println(“Sentence must be
within the limit of 100 characters”)
}
else
{
for(i=0;i<len && result=false;i++)
{
ch1=w.charAt(i);
for(j=0;j<I;j++)
{
ch2=w.charAt(j);
if(ch1==ch2)
{
result=true;
break;
}
}
}
return(result);
}
public static String subString (String s1)
{
int i,j,len1,len2;
char ch1,ch2;
len1=s1.length();
String s2=” ”,s3=” “,max=” “;
for(i=0;i<len1;i++)
{
s2=” “;
for(j=i+1;j<len1;j++)
{
s2=s1.substring(i,j);
if(isRepeated(s2))
{
s2=s2.substring(0,s2.length()-1);
break;
}
}
if(s2.length()>max.length())
{
max=s2;
}
}
return(max);
}
public static void main()
{
Scanner in=new Scanner(System.in);
int i,n;
String s1,s2;
System.out.println(“Enter a sentence”);
if(s1<=100)
{
s1=in.nextLine();
String Tokenizer st=new StringTokenizer(s1);
n=st.countTokens();
for(i=1;i<=n;i++)
{
s2=st.nextToken();
System.out.println(s2+” “+substring(s2));
}
}
}
Sample Input:
Enter a string of not more than 100 characters
Management is a skill.
Sample Output:
MANAGEMENT NAGEM
IS IS
A A
SKILL SKIL

You might also like