Sie sind auf Seite 1von 1

string.

java
import java.io.*;
class PM
{
int pm(String x,String y,int l,int m,int start)
{
int j;
for(int i=start;i<=l-m;i++)
{
j=0;
while(y.charAt(j)==x.charAt(i+j))
{
j++;
if(j==m)
return i;
}
}
return -1;
}
}
class string
{
public static void main(String s[])throws IOException
{
String x,y;
PM p=new PM();
DataInputStream ds=new DataInputStream(System.in);
System.out.println("Enter 2 strings:");
x=ds.readLine();
y=ds.readLine();
int l=x.length();
int m=y.length();
int r=p.pm(x,y,l,m,0);
if(r==-1)
System.out.println("NO SUCH STRING IS FOUND");
else
System.out.println("FOUND AT LOCATION:"+(r+1));
}
}

Page 1

Das könnte Ihnen auch gefallen