Question

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import java.util.Scanner;

public class Palindrome {
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a string: ");
        String s1 = scanner.nextLine().toLowerCase();
        String r = "";

        int size = s1.length();
        for(int i = size-1;i>=0;i--)
            r = r + s1.charAt(i);
        if (s1.equals(r)) {
            System.out.println(s1 + " is palindrome");
        } else {
            System.out.println(s1 + " is not palindrome");
        }
    }
}

Output:

Enter a string: radar radar is palindrome Process finished with exit code o

Add a comment
Know the answer?
Add Answer to:
1) IN JAVA Write a short program that tests if an inputted word is a palindrome....
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 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...

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

  • Concepts: Pointers and pointer arrays Write a program to read in a phrase from the keyboard,...

    Concepts: Pointers and pointer arrays Write a program to read in a phrase from the keyboard, re-display the text, and display a message on the following line giving the text's status as a palindrome. Do not use any arrays or subscripting in this program, except for arrays of pointers. A palindrome is a word or phrase which is the same backwards as forwards; for example "civic", "toot", and "radar" are palindrome words; each word is spelled the same left to...

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

  • Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a str...

    Please Code in Java and follow the directions given Thanks Program required Directions .A palindrome is a string that reads the same forward and backward, i.e., the letters are the same whether you read them from right to left or from left to right. Examples: 3 a) radar à is a palindrome b)Able was I ere I saw Elba à is a palindrome e good à not a palindrome Write java program to read a line of text and tell...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

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

  • Could you guys write an efficient java program to implement BST. Your java program should read...

    Could you guys write an efficient java program to implement BST. Your java program should read words and its corresponding French and store it in a BST. Then read every English word and print its corresponding French by searching in BST. Assume your java program is in xxxxx5.java file (5th java project), where xxxxx is the first 5 characters of your last name. To compile: javac xxxxx5.java To execute: java xxxxx5 < any data file name Your main method should...

  • Please write in java Write a main program that runs the following two recursive methods demonstrating...

    Please write in java Write a main program that runs the following two recursive methods demonstrating that they work. #1) Write a recursive method writeSquares that accepts an integer n and prints the first n squares with the odd squares in decending order, followed by the even squares in acending order. For example • writeSquares(8): prints . 49 25 9 1 4 16 36 64 • writeSquares(11); prints 121 81 49 25 9 1 2 16 36 64 100 •...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

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