public static void main(String[] args) { StringFind sf = new StringFind(); System.out.println(sf.find(5)); }
public int find(int n) { String test = "1,3,10,6,25,40,9";
Pattern p = Pattern.compile(","); Matcher m = p.matcher(test); int i = 0; while (m.find()) { i++; if (n == i) return m.start(); } return -1; }楼主想要这样的吗? 你要记得给分啊
StringFind sf = new StringFind();
System.out.println(sf.find(5));
}
public int find(int n) {
String test = "1,3,10,6,25,40,9";
Pattern p = Pattern.compile(",");
Matcher m = p.matcher(test);
int i = 0;
while (m.find()) {
i++;
if (n == i)
return m.start();
}
return -1;
}楼主想要这样的吗?
你要记得给分啊