Other 2015 FR Questions FR other years Be Prepared Home
A-2
public class HiddenWord
{
  private String word;
  
  public HiddenWord(String w)
  {
    word = w;
  }  

  public String getHint(String s)
  {
    String hint = "";
    
    for (int i = 0; i < s.length(); i++)
    {
      String letter = s.substring(i, i+1);
      
      if (letter.equals(word.substring(i, i+1))) 1
        hint += letter;
      else if (word.indexOf(letter) >= 0)
        hint += "+";
      else
        hint += "*";
    }
    
    return hint;
  }
}
Notes:
  1. Not letter == word.substring(i, i+1)

Other 2015 FR Questions | Back to Contents

Copyright © 2015 by Skylight Publishing
support@skylit.com