//一个英文单词接龙游戏,不只是最后一个字母
//比如the后面可以接e开头的,也可以接he开头的
import java.util.Scanner;
public class Test {
public static String jieLong(String str1,String str2){
String head="";
String tail="";
int len=str1.length()
for (int i = 0; i
head=str2.substring(0, i+1);
tail=str1.substring(str1.length()-1-i,str1.length());
if (head.equals(tail)) {
return head;
}
}
return null;
}
public static void main ( String[] args ){
Scanner sc = new Scanner (System.in);
System.out.println("请输入第一个单词");
String str1 = sc.next();
int count=1;
while (true) {
System.out.println("输入接龙单词");
String str2 = sc.next();
String result = jieLong(str1, str2);
if (result != null) {
count++;
str1=str2;
System.out.println(result);
} else {
System.out.println("接龙失败");
System.out.println("共接龙"+count+"次");
break;
}
}
}
}