public class Test {
public static void main(String args[]) {
System.out.println("Please enter one sentence:");
java.util.Scanner scanner = new java.util.Scanner(System.in);
String sentence = scanner.nextLine();
System.out.println("Please enter the key:");
String pattern = scanner.next();
int index = -1;
while ((index = sentence.indexOf(pattern, index + 1)) >= 0) {
System.out.print(index + " ");
}
}
}