So I've created this program which manipulates a word that the user gives as input, by taking the moving the first character to the end of the word, spells the rest of the word backwards, then checks if the original word and the new word are the same. It's designed to run until the user enters the word "quit" as the chosen word. I've managed to get the majority of the code working, except, instead of looping back to ask the user for a new word after its checked the previous one, it just continues running forever. The code I've currently got is below:
package uploadTask9_wordPlay;
import java.util.Scanner;
public class wordPlay {
public static void main(String[] args) {
// creates scanner object to get a name from the user input
Scanner userInput = new Scanner(System.in);
System.out.println("Enter a name to be tested, or 'quit' to exit
program: ");
// stores the user input into string testedName
String testedName = userInput.nextLine();
// if the user input is "quit", program exits
if (testedName.equals("quit")) {
System.out.println("Thanks for using the program");
System.exit(0);
}
// else, do the rest of the code with the given word
else {
while (testedName != "quit") {
// takes first character from userInput
char firstLetter = testedName.charAt(0);
// removes first character from testedName
StringBuilder removeChar = new StringBuilder(testedName);
removeChar.deleteCharAt(0);
// adds first character of testedName to the end of removeChar
String newString = removeChar.toString() + firstLetter;
// prints newString backwards
String reverseWord = new
StringBuffer(newString).reverse().toString();
// if statement - far simpler way to carry this task out than loops
// if statement to check if the words are the same
if (testedName.equals(reverseWord)) {
System.out.println(testedName + " is the same as " + reverseWord); }
else {
System.out.println(testedName + " is not the same as " + reverseWord); }
}
}
}
}
Does anyone know why the program doesn't loop back to the start each time its checked a word?