title: How do you find words in a text file and print the most frequent word shown using array?
body: <p>I'm having trouble of figuring out how to find the most frequent word and the most frequent case-insensitive word for a program. I have a scanner that reads through the text file and a while loop, but still doesn't know how to implement what I'm trying to find. Do I use a different string function to read and print the word out?</p>
  
  <p>Here is my code as of now:</p>
  
  <pre><code>public class letters {
  public static void main(String[] args) throws FileNotFoundException {
      FileInputStream fis = new FileInputStream("input.txt");
      Scanner scanner = new Scanner(fis);
      String word[] = new String[500];
      while (scanner.hasNextLine()) {
          String s = scanner.nextLine();
          for (int i = 0; i &lt; s.length(); i++) {
              char ch = s.charAt(i);
               }
  
            }
        String []roll = s.split("\\s");
         for(int i=0;i&lt;roll.length;i++){
             String lin = roll[i];
             //System.out.println(lin);
        }
   }
  </code></pre>
  
  <p>This is what I have so far. I need the output to say:</p>
  
  <pre><code>   Word:
     6 roll
  
    Case-insensitive word:
    18 roll
  </code></pre>
  
  <p>And here is my input file:</p>
  
  <pre><code>@
  roll tide roll!
  Roll Tide Roll!
  ROLL TIDE ROLL!
  ROll tIDE ROll!
   roll  tide  roll! 
   Roll  Tide  Roll! 
   ROLL  TIDE  ROLL! 
     roll    tide    roll!   
      Roll Tide Roll  !   
  @
  65-43+21= 43
  65.0-43.0+21.0= 43.0
   65 -43 +21 = 43 
   65.0 -43.0 +21.0 = 43.0 
   65 - 43 + 21 = 43 
   65.00 - 43.0 + 21.000 = +0043.0000 
      65   -  43  +   21  =   43  
  </code></pre>
  
  <p>I just need it to find the most occuring word(Which is the maximal consecutive sequence of letters)(which is roll) and print out how many times it is located(which is 6) . If anybody can help me on this, that would be really great! thanks</p>