如何在 a 中找到一个字符String
并在整个字符串中打印字符的位置?例如,我想'o'
在这个字符串中找到 :的位置"you are awesome honey"
并得到答案 = 1 12 17
。
我写了这个,但它不起作用:
public class Pos {
public static void main(String args[]){
String string = ("You are awesome honey");
for (int i = 0 ; i<string.length() ; i++)
if (string.charAt(i) == 'o')
System.out.println(string.indexOf(i));
}
}