gpt4 book ai didi

java - 使用indexOf搜索时输出错误

转载 作者:行者123 更新时间:2023-12-01 15:53:54 25 4
gpt4 key购买 nike

 int locsPlusLast = locsPlus.get(locsPlus.size()-1);
System.out.println(locsPlusLast);
int index = checkScanning.indexOf('(',locsPlusLast);
while(index>=0){
index = checkScanning.indexOf('(',locsPlusLast+1);
System.out.println(index);
}

checkScanning是扫描仪输入。

我只想输出(,但它输出)两个的位置,为什么?

最佳答案

抱歉,我误解了你的问题。
试试这个:

private static void positionOf(char target, String query) {

int position = 0;
int result = 0;

while(-1 != (result = query.indexOf(target, position))){

System.out.println(result);
position = result +1;
}
}

关于java - 使用indexOf搜索时输出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5455288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com