public static void main(String[] args) {
String str = "samosa";
int firstIndex = str.indexOf('s');
int lastIndex = str.lastIndexOf('s');
System.out.println("First occurrence of 's' in " + str + " is at index " + firstIndex);
System.out.println("Last occurrence of 's' in " + str + " is at index " + lastIndex);
}
}
No comments:
Post a Comment