100行左右的java动物类型大作业_求 100行左右的java游戏小程序 我是小白 老师要求的 有木有大神解救啊...

//一个英文单词接龙游戏,不只是最后一个字母

//比如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;

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值