This will work, assuming that each word is separated by a space. I've added the main function for clarity. The find_str returns -1 if the word doesn't exist. otherwise, it returns the position of the word with respect to other words. Here, 2 will be returned, meaning that the second word is 'am'.
import java.util.*;
public class HelloWorld{
public static void main(String []args){
String str="I am a Java Programmer";
String str1="am";
int x=find_str(str,str1);
System.out.println(x);
}
public static int find_str(String main,String search) {
int i;
int found=-1;
String[] s=main.split(" ");
for(i=0;i<s.length;i++)
{
if(search.equals(s[i]))
found=i+1;
}
return found;
}
}