Preview:
import java.util.Scanner;
public class Indices {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Enter the string");
        String s = sc.nextLine();
        System.out.println("Enter the word");
        String wr = sc.nextLine();
        findind(s,wr);
    }
    private static void findind(String s, String wr) {
        int index = s.indexOf(wr);
        while(index!=-1){
            System.out.println("Index of "+wr+" :"+index);
            index = s.indexOf(wr,index+1);
        }
        if(index==-1&&s.indexOf(wr)==-1){
            System.out.println("The word "+wr+" is not found");
        }
    }
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter