indices
Thu Jan 18 2024 18:21:13 GMT+0000 (Coordinated Universal Time)
Saved by
@login
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");
}
}
}
content_copyCOPY
Comments