Chart()method

DBRBZYY 2005-10-13 09:50:26
编写一个方法来查找在另一个字符串里的特定字符串。如果字符串存在,则方法必须返回真。例如:isSubString(“cat”, “The cat in the hat.”)是true,而isSubString( “bat”, “The cat in the hat.”)是false。
另外,验证边界条件也要遇到。
 isSubString(“The”, “The cat in the hat,”)是true
 isSubString(“hat.”, “The cat in the hat.”)是true。
提示-可以使用String类的charAt(int index)方法找到某个字符串中的特定字符;index是从0开始。例如:“cat”.charAt(0)是‘c’、 “cat”.charAt(1)是 ‘a’、 “cat”.charAt(2)是 ‘t’。length方法返回字符串中的字符数目:例如:“cat”.length()是3。

我初学JAVA请那位大哥帮我解决一下!本人在此先说声谢谢了。
我编的太麻烦了!
...全文
69 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Z_Beginner 2005-10-13
  • 打赏
  • 举报
回复
import java.util.regex.*;

class Regex1{
public static void main(String args[]) {
System.out.println("是否存在?"+isSubstring(args[0],args[1]));
}
public static boolean isSubstring(String s1,String s2){
Pattern p = Pattern.compile(s1);
Matcher m = p.matcher(s2);
return m.find();
}
}
treeroot 2005-10-13
  • 打赏
  • 举报
回复
String.indexOf("XXX")!=-1

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧