title: Reversing characters in each word in a sentence - Stack Implementation
body: <p>This code is inside the <code>main</code> function:</p>
  
  <pre><code>Scanner input = new Scanner(System.in);
  
  System.out.println("Type a sentence");
  String sentence = input.next();
  
  Stack&lt;Character&gt; stk = new Stack&lt;Character&gt;();
  int i = 0;
  
  while (i &lt; sentence.length())
  {
      while (sentence.charAt(i) != ' ' &amp;&amp; i &lt; sentence.length() - 1)
      {
          stk.push(sentence.charAt(i));
          i++;
      }
      stk.empty();
      i++;
  }
  </code></pre>
  
  <p>And this is the <code>empty()</code> function:</p>
  
  <pre><code>public void empty()
  {
      while (this.first != null)
          System.out.print(this.pop());
  }
  </code></pre>
  
  <p>It doesn't work properly, as by typing <code>example sentence</code> I am getting this output: <code>lpmaxe</code>. The first letter is missing and the loop stops instead of counting past the space to the next part of the sentence.</p>
  
  <p>I am trying to achieve this:</p>
  
  <p><code>This is a sentence</code> --->  <code>sihT si a ecnetnes</code></p>