我想有這樣的代碼能夠找到一個以上的X和輸出它作爲LOCATION1,LOCATION2,.......多於一個索引
即輸入:xuyx 我將有它輸出0,3
import java.util.Scanner;
public class findinline {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str;
str = input.nextLine();
int pos = str.indexOf("x");
if (pos < 0){
System.out.println("No X Detected");
}
else{
System.out.println(pos);
}
}
}
可能的重複[Java - 字符串中所有出現字符的索引](http://stackoverflow.com/questions/5034442/java-indexes-of-all -occurrences-的字符-IN-A-字符串) – EvenPrime 2014-09-04 20:22:10