title: java program to loop back to start
body: <p>I am trying to get this program to loop back and start again when the user wants to try another word. I have tried a while loop but couldn't figure it out. I am a newbie to programming so any help is appreciated.  </p>
  
  <pre><code>import java.util.Scanner;
  
  
  public class PEX5{
  
      public static void main(String[] theArgs){
  
          int numLetters;
          char fromStack;
          char fromQueue;
          int charCount;
  
          String x;
  
          UnboundedStackInterface&lt;Character&gt; myStack = new LinkedStack&lt;Character&gt;();
          UnboundedQueueInterface&lt;Character&gt; myQueue = new LinkedUnbndQueue&lt;Character&gt;();
  
          System.out.println("Enter a word to check for Palindrome");
  
          @SuppressWarnings("resource")
          Scanner keyboard = new Scanner(System.in);
  
          x = keyboard.nextLine();
  
          int i;
          numLetters = 0;
  
          for(i = 0; i &lt; x.length(); i++){
              Character ch = x.charAt(i);
  
              numLetters++;
  
              myStack.push(ch);
              myQueue.enqueue(ch);
          }
  
          charCount = 0;
  
          while(charCount &lt;= numLetters) {
  
              fromStack = myStack.top();
              myStack.pop();
              fromQueue = myQueue.dequeue();
  
              if(fromStack != fromQueue)
                  System.out.println("Not Palindrome");
  
              if(fromStack == fromQueue) {
                  charCount++;
                  System.out.println("Palindrome");
              }
  
              System.out.println("Would you like to try another? (Y = yes  N = no): ");
              x = keyboard.nextLine();
              System.out.println("");
          }
  
      }
  }
  </code></pre>