编写一个方法来查找在另一个字符串里的特定字符串。如果字符串存在,则方法必须返回真。例如: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请那位大哥帮我解决一下!本人在此先说声谢谢了。
我编的太麻烦了!
另外,验证边界条件也要遇到。
 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请那位大哥帮我解决一下!本人在此先说声谢谢了。
我编的太麻烦了!
解决方案 »
- 100分求助!!java 制作彩信!
- PreparedStatement 插入空值
- 对于Double型的比较然后输出较大值
- java怎么读取doc和rtf格式的内容到txt文件中???
- The Network Adapter could not establish the connection
- 请教关于类方法的参数问题
- 一個很菜的問題-請問jdk 怎樣配置后才能用
- 为什么我每次都是问的初级问题
- 如何实现 类似 "关于对话框"的东西.最好用Swing........
- 怎么学习java?
- 求助 .第一次使用JB时的错误..老鸟不要笑话
- 关于使用 jacob(java 与com交互的桥)操作word ,感受与大家分享
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();
}
}