关于java中indexof的问题

武林豪杰的小跟班 2017-12-08 07:38:11
先贴出实验代码:
public class Test {
public static void main(String[] args) {
String optstr = "adasjjas.kdfg";
String result = indexOfAll(optstr, "as");
System.out.println(result.equals("2,6"));
}

public static String indexOfAll(String optstr, String string) {
待填补代码;
return null;
}
}
而我自己写的填补代码在下面 一直报错 运行不出来,填补的代码是要实现main方法里面的indexOfAll方法 求教大佬指点怎么写
int a[]=null;
while (optstr != null) {
for (int i=0;i<optstr.length();i++) {
a[i]=optstr.indexOf(string);
optstr.substring(optstr.indexOf(string));
}
}
return "a[0],a[1]";
...全文
201 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bcvb 2017-12-09
  • 打赏
  • 举报
回复
你的a数组是空。。。。
天之上有什么 2017-12-09
  • 打赏
  • 举报
回复
String str =  optstr.indexOf("as")+","+optstr.lastIndexOf("as");
		return str;

58,452

社区成员

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

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