title: clearing a java string after loop
body: <p>I am new to Java and am creating a project for class that basically asks the user to input a string, and then tests the string and prints whether or not it is a palindrome (the same forwards as backwards... i.e. mom or dad or racecar)</p>
  
  <p>I have gotten the code to work, however i have a loop setup to rerun the program or quit at the end.  My problem is that when you rerun the program and enter another String input then it's adding it to the original string.</p>
  
  <p>How can I reset or delete the String input each time so that it starts fresh?</p>
  
  <p>Thank you for any help!  Also please note, there may be better or faster ways to accomplish what I have done here but my knowledge of java is limited and I am just getting started, so I have used the knowledge that I have thus far learned.  Thanks!!</p>
  
  <pre><code>import java.util.Scanner;
  public class Palindrome {
    public static void main(String[] args) {
  
        String input = ""; // Word entered by user
        String reverse = ""; //Reverse of String input
        String redoAnswer; // answer to rerun program
  
        int length; //length of word entered by user
  
        boolean test;
        boolean redo; // boolean to rerun program
        boolean exit; // boolean to validate exit/rerun
  
  
        Scanner scan = new Scanner(System.in);
  
        do {
          redo = true;
          exit = true;
  
          System.out.println("Please enter a string: ");
          input = scan.nextLine();
  
          length = input.length();
  
          for (int i = length - 1; i &gt;= 0; i--)
            reverse = reverse + input.charAt(i);
  
          if (input.equalsIgnoreCase(reverse)) {
            System.out.println("Yes, this string is a palindrome!");
          } else {
  
            System.out.println("Sorry, this string is NOT a palindrome!");
          }
  
          do {
            System.out.println("Please type r to restart or q to quit");
            redoAnswer = scan.nextLine().trim().toLowerCase();
            if (redoAnswer.equals("r")) {
              exit = false;
              redo = true;
              continue;
            } else if (redoAnswer.equals("q")) {
              exit = false;
              redo = false;
              System.out.println("Goodbye!");
              continue;
            } else {
              System.out.println("Sorry, I didn't catch that.");
              continue;
            }
          } while (exit);
        } while (redo);
      } //end main
  } //end class
  </code></pre>
  
  <p>Ok, figured it out thanks to your guys' help... also rewrote the code so that you can just keep entering new strings or type q to quit instead of the redo question at the end.  Hopefully this is cleaner!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import java.util.Scanner;
  public class Palindrome_Test {
    public static void main(String[] args) {
        String input = ""; // Word entered by user
        String reverse = ""; //Reverse of String input
  
        int length; //length of word entered by user
  
        boolean redo = true; // boolean to rerun program
  
        Scanner scan = new Scanner(System.in);
  
        do {
          System.out.println("Please enter a string, or type Q to quit: ");
          input = scan.nextLine();
          if (input.equalsIgnoreCase("q")) {
            System.out.println("Goodbye!");
            redo = false;
          } else {
            length = input.length();
            for (int i = length - 1; i &gt;= 0; i--)
              reverse = reverse + input.charAt(i);
  
            if (input.equalsIgnoreCase(reverse)) {
              System.out.println("Yes, this string is a palindrome!");
            } else {
              System.out.println("Sorry, this string is NOT a palindrome!");
            }
            reverse = "";
          }
        } while (redo);
      } //end main
  } //end class</code></pre>
  </div>
  </div>
  </p>