Question

A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...

A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run.

In this program, ask the user to input some text and print out whether or not that text is a palindrome.

Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome.

Create the method reverse which reverses a String and returns a new reversed String to be checked by isPalindrome.

Both methods should have the signature shown in the starter code.

Sample output:

Type in your text: 
madam
Your word is a palindrome!

OR

Type in your text: 
hello
Not a palindrome :(

Coding Portion:

public class Palindromes
{
/**
* This program lets the user input some text and
* prints out whether or not that text is a palindrome.
*/
public static void main(String[] args)
{
// Create user input and let user know whether their word is a palindrome or not!
  
}
  
/**
* This method determines if a String is a palindrome,
* which means it is the same forwards and backwards.
*
* @param text The text we want to determine if it is a palindrome.
* @return A boolean of whether or not it was a palindrome.
*/
public static boolean isPalindrome(String text)
{
// Your code goes here!
}
  
/**
* This method reverses a String.
*
* @param text The string to reverse.
* @return The new reversed String.
*/
public static String reverse(String text)
{
// Your code goes here!
}

}

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

Code:

Output:

Raw Code:

import java.util.*; // Importing required packages
public class Palindromes{
   public static void main(String[] args) {
       System.out.println("Type in your text:");
       Scanner scan = new Scanner(System.in); // Creating Scanner instance for taking input from user.
       String str = scan.next(); // Taking string from user and store it in str variable.
       if (isPalindrome(str)){ // Checking if a str is palindrome or not.
           System.out.println("Your word is a palindrome!");
       }
       else{ // If it is not a palindrome
           System.out.println("Not a palindrome :(");
       }
   }
   // isPalindrome function for checking if a given string is palindrome or not.
   public static boolean isPalindrome(String text){
       String reverse_text = reverse(text); // Calling reverse function with text as a parameter.
       if (text.equals(reverse_text)){ // Checking if a text and reverse_text are equal or not
           return true; // Returning true
       }
       else{
           return false; // Returning false
       }
   }

   public static String reverse ( String text){
       String rev = ""; // Declaring rev variable.
       for (int i = text.length() -1;i>=0;i--){ // Iterate through each character in text in reverse order.
           rev += text.substring(i,i+1); // adding each character to rev.
       }
       return rev; // Returning the rev.
   }
}


Note : If you have any doubts plz ask me in comment section.

Add a comment
Know the answer?
Add Answer to:
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...
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
  • 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....

  • C++ A palindrome is a string that reads the same backward as forward. For example, the...

    C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...

  • 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...

  • C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string cl...

    C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...

  • Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba,...

    Python Question: A palindrome is a string that reads identical forwards and backwards. Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc. Your task is to write a function ispalindrome(string) that reads an input string and returns True if both of the following are true: The string is a palindrome The string has at least one letter (uppercase or lowercase) For example: ispalindrome('racecar') should return True PS: ispalindrome('123321') should return False ispalindrome('racecar') should return True

  • A palindrome is a sequence of characters that reads the same backwards as forward. For example,...

    A palindrome is a sequence of characters that reads the same backwards as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554, and 11611. Create an application that accepts a five-digit integer and determines whether it's a palindrome. Assume the user will enter only five digits, and never enter 0 as the first digit. I need the answer in visual studios please.

  • [30 points] Question 3 A palindrome is a string that reads identical forwards and backwards Examples...

    [30 points] Question 3 A palindrome is a string that reads identical forwards and backwards Examples include abba, abcba, a1b1b1a, houstonnotsuoh etc Your task is to write a program that reads an input string prints that string, and then prints one of the following as appropriate: Is a Palindrome or Nota Palindrome I user response is input - racecar, the above program should print гacecar Is a Palindrome If user response is input = hello, the above program should print...

  • palindrome is a string that reads the same both forward and backward. C++ For example, the...

    palindrome is a string that reads the same both forward and backward. C++ For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.

  • 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...

  • A palindrome is a sequence of characters that reads the same backward as forward. For example,...

    A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it's a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

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