Question

– Palindrome Game Please write a Java program to verify whether a given word is a...

– Palindrome Game

Please write a Java program to verify whether a given word is a palindrome. You must stop your program when the user enters ‘@’ character as the word.

You may write a recursive program to solve this game, but you don’t have to.

You may use a stack and/or a queue to solve this game, but you don’t have to.

You must run 3 test cases for your program.   Your test case #1 must look as follows:

Welcome to the Palindrome World of Dr. Simon Lin!

Please enter a word (@ to quit) > racecar

The word racecar is a palindrome.

Please enter a word (@ to quit) > racersrecar

The word racersrecar is a palindrome.

Please enter a word (@ to quit) > racescar

The word racesar is NOT a palindrome.

Please enter a word (@ to quit) > mom

The word mom is a palindrome.

Please enter a word (@ to quit) > teacescaet

The word teacescaet is NOT a palindrome.

Please enter a word (@ to quit) > q

The word q is a palindrome.

Please enter a word (@ to quit) > @

Thank you for playing this Palindrome game designed by Dr. Simon Lin!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class PlaindromeRecursion {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Please enter a word (@ to quit) ");
       String word = sc.nextLine();
       while (!word.equals("@")) {
           if (isPalRec(word, 0, word.length() - 1)) {
               System.out.println("The word " + word + " is a palindrome.");
           } else {
               System.out.println("The word " + word + " is a NOT a palindrome.");
           }
           System.out.println("Please enter a word (@ to quit) ");
           word = sc.nextLine();

       }
       System.out.println("Thank you for playing this Palindrome game designed by Dr. Simon Lin!");
   }

   static boolean isPalRec(String str, int s, int e) {
       // If there is only one character
       if (s == e)
           return true;

       // If first and last
       // characters do not match
       if ((str.charAt(s)) != (str.charAt(e)))
           return false;

       if (s < e + 1)
           return isPalRec(str, s + 1, e - 1);

       return true;
   }
}

Add a comment
Know the answer?
Add Answer to:
– Palindrome Game Please write a Java program to verify whether a given word is a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward...

    Palindrome Detector C++ A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for...

  • Sudoku Game Real Please write a Java program to play a Sudoku game and show its...

    Sudoku Game Real Please write a Java program to play a Sudoku game and show its winning result. This is an application program of using 2-dimensional arrays.   Each array is for a game board of 9 x 9. Your program must know how to play Sudoku game and complete the game with a winning result. The following is a sample test, which must be all your test cases. As you can see, you must pre-load the following 4 games into...

  • A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here...

    A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for the user input....

  • 1) IN JAVA Write a short program that tests if an inputted word is a palindrome....

    1) IN JAVA Write a short program that tests if an inputted word is a palindrome. A palindrome is a word that is spelled exactly the same forward and backwards such as radar or mom. You must look at individual characters for the solution, do not use a premade method such as reverse! ALSO DO THIS IN ONE SINGULAR MAIN WITH NO STATIC METHODS

  • Palindrome is a word or a phrase when taken in reverse order, gives the same word...

    Palindrome is a word or a phrase when taken in reverse order, gives the same word or phrase. For example, the word “radar” is a palindrome. The phrase "Do geese see God?" is also a palindrome after the removal of the question mark and all the spaces and the conversion of the remaining alphabets to either upper or lower case. Write a program that uses an STL stack to check if an arbitrary string containing multiple words separated by spaces...

  • Write a MATLAB program that requests the user to enter a word and checks if the...

    Write a MATLAB program that requests the user to enter a word and checks if the word is a palindrome or not. Test the program with following inputs. 1. racecar 2. Levels 3. civic

  • 22.7 Lab: Word ladder Write a word ladder program. Read this wikipedia article that describes what...

    22.7 Lab: Word ladder Write a word ladder program. Read this wikipedia article that describes what a word ladder is: Word Ladder Your program must use a list to store the dictionary of words and then use stacks of strings and a queue of these stacks to solve for and output the word ladder. You are required to use the Standard Template Library (STL) list, stack, and queue. You must implement the WordLadder class. The class is declared in WordLadder.h....

  • Write a Java program that checks the properness of a given variable name. More specifically, your...

    Write a Java program that checks the properness of a given variable name. More specifically, your program should specify whether a user-entered variable name is illegal (no spaces allowed, must begin with a letter) legal, but uses poor style (should only use letters or digits) good You don’t need to check for an uppercase letter for the first letter in the second word, third word, etc. Sample session: This program checks the properness of a proposed Java variable name. Enter...

  • Please write a recursive Java program to solve the Tower of Hanoi game for n disks...

    Please write a recursive Java program to solve the Tower of Hanoi game for n disks on pole A. Please read the textbook page 176 – 180 to fully understand this game or puzzle. The game consists of n disks and three poles: A (the source), B (the destination), and C (the spare). Initially, all the disks are on pole A. The game is to move all disks (one by one) from pole A to pole B using pole C...

  • Write a C++ program to check whether a string is a palindrome. Input a string (word)...

    Write a C++ program to check whether a string is a palindrome. Input a string (word) from the keyboard. Assume the letters are case-insenstive. Use the C++ string class. Refer to the sample output below. Sample Runs: Enter a string: otto; otto is a palindrome Enter a string: A A is a palindrome Enter a string: heooh heooh is not a palindrome

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT