Java实现BF算法(字符简单匹配)
import java.awt.desktop.SystemEventListener;
import java.util.*;
public class bF {
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
String a1=input.nextLine();
String a2=input.nextLine();
String[] s1 = a1.split("");
String[] s2 = a2.split("");
int i=0,j=0,start=0;
while (i< s1.length && j<s2.length)
{
if(s1[i].equals(s2[j]))
{
i++;j++;
}
else
{
j=0;
start++;
i=start;
}
}
start++;
if(j==s2.length)
System.out.println("s2是s1的字串,位置为:"+start);
else
System.out.println("不匹配,s2不是s1的字串");
}
}