title: # of times a single word in a sentence
body: <p>How can i get the # of times a single word is in a given sentence.. String.split cannot be used.. I don't really need the code. I just need an idea to get started..</p>
  
  <pre><code>package exam2;
  
  import java.util.Arrays;
  
  public class Problem2 {    
      /**
       * @param args
       */    
      public static String input, word, a, b, c;
      public static int index;
  
      public static void Input() {    
          System.out.println("Enter Sentence: ");
          input = IO.readString();
  
          System.out.println("Enter Word: ");
          word = IO.readString();    
      }
  
      public static void Calc() {    
          Input();    
          index = input.indexOf(word);    
          int[] data = new int[input.length()];    
          data[0] = index;
  
          while (index &gt;= 0) {
              System.out.println("Index : " + index);
              for (int i = 1; i &lt; data.length; i++) {
                  data[i] = index;    
              }
              index = input.indexOf(word, index + word.length());    
          }
  
          int count = 0;
          for (int i = 0; i &lt; data.length; i++) {    
              for (int j = 0; j &lt; data.length; j++) {
                  if (data[i] == data[j]) {    
                      a = input.substring(data[i], data[i] + word.length());    
                  }    
                  else if (data[i] != data[j]) {    
                      b = input.substring(data[i], data[i] + word.length());    
                      c = input.substring(data[j], data[j] + word.length());
                  }    
              }    
          }
          if (a.equalsIgnoreCase(word)) {    
              count++;
          }    
          System.out.println(count);    
      }
  
      public static void main(String[] args) {
          Calc();  
      }    
  }
  </code></pre>
  
  <p>using a while loop i finding the index of word given by the user in the sentence again given by the user.. I am storing those index in the array. for some reason that is not working.. so i found another way of implementing it. if the index of that word in the array is the equals each other then the word only exits once. I have got this to work.. but if the word exits more than once that is creating the problem..</p>