Q:

Return the anagram of the first word that has appeared in the second word.

Given two words, determine if the first word, or any anagram of it, appears in consecutive characters of the second word. For instance, tea appears as an anagram in the last three letters of slate, but let does not appear as an anagram in slate even though all the letters of let appear in slate.
Return the anagram of the first word that has appeared in the second word. 
Sample Input 1
tea
slate

Sample Output1
ate
Sample Input 2
let
slate

Sample Output2
NONE

I tried below got struck
public static boolean testAnagram(String originalWord, String containedWord)
{
char [] first = originalWord.toCharArray();//Get the first word and store it into a character array.
char [] second = containedWord.toCharArray();//Get the second word and store it into a character array.
int [] index = new int[second.length];//An int array that stores the index of matching letters contained in the original array.
int counter = 0;//Keep count of the index storage position.

//Compare each character of both words.

for(int i = 0; i < second.length; i++)
{
  for(int j = 0; j < first.length; j++)
  {
    if(second[i] == first[j])
    {
      index[counter] = j; //Store matching letters.
      counter++; //Increment the index storage position.
      break;//Break for loop.
    }
  }
}

if(counter < second.length)return false;//If not all letters were found.

//get the distance between the indices which should be no more than one
//less than the contained word length (to qualify as an anagram)

for(int i = 0; i < index.length; i++)
{
  for(int j = 0; j = second.length) 
  {
    //stuck here
    return ;
  }
}

//If all qualifications are met.
return ;
}

A:

I suggest you do the following:

Iterate through each character in the second word (ex. slate)
When you find a character contained in the first word, get the substring that begins at this character with the length of the first word.
Check if this substring is an anagram of the first word.
 String getSubAnagram (String s1, String s2){
        for (int i = 0; i = s1.length(); i++) {
            if(s1.indexOf(s2.charAt(i)) >-1){
                if(isAnagram(s1, s2.substring(i, s1.length()+i)))
                    return s2.substring(i, s1.length()+i);
            }
        }
        return null;
 }

