Question

In: Computer Science

Java Palindrome Use StringBuilder concept to create a palindrome checker.   Method should be called pCheck. Must...

Java Palindrome

Use StringBuilder concept to create a palindrome checker.  

Method should be called pCheck.

Must use var-arg concept.  

Class name for this program is Palindrome.  

Must pass this test::

public class PalindromeTest {

public static void main(String[] args) {

Palindrome palindrome = new Palindrome();

boolean answer = palindrome.pCheck("racecar", "Bell", "elle", "bunny");

System.out.println(“These are palindromes: " + answer);

}

}

Solutions

Expert Solution

If you have any doubts, please give me comment...

Here I used if all the strings are palindromes, then pCheck method returns true otherwise returns false.

class Palindrome{

    public boolean pCheck(String...strings){

        for(int i=0; i<strings.length; i++){

            int len = strings[i].length();

            for(int j=0; j<len/2; j++){

                if(strings[i].charAt(j)!=strings[i].charAt(len-j-1))

                    return false;

            }

        }

        return true;

    }

}

public class PalindromeTest {

    public static void main(String[] args) {

        Palindrome palindrome = new Palindrome();

        boolean answer = palindrome.pCheck("racecar", "Bell", "elle", "bunny");

        System.out.println("These are palindromes: " + answer);

    }

}

Let me know if any output differ... Thank you...


Related Solutions

(Using Java) create a class that can identify a palindrome. A palindrome is defined as -...
(Using Java) create a class that can identify a palindrome. A palindrome is defined as - A string of characters that reads the same from left to right as its does from right to left - Example: Anna, Civic, Kayak, Level, Madam - To recognize a palindrome, a queue can be used in conjunction with a stack o A stack can be used to reverse the order of occurrences o A queue can be used to preserve the order of...
Create a java program that will do the following: Create a method called getInt.Allow the user...
Create a java program that will do the following: Create a method called getInt.Allow the user to enter up to 20 student names,and for each student 3 quiz scores (in the range 0-100). Once input is done, display each student’s name, their three quiz scores, and their quiz score average, one student per line. The output table does not need to line up perfectly in columns.Use dialog boxes for all input and output.Use the method to input the three scores.Parameter...
Meant to be written in Java JDK 14.0 A String object is called palindrome if it...
Meant to be written in Java JDK 14.0 A String object is called palindrome if it is same when read from the front and the end. For example, String “abcba” is palindrome, while “12322” is not. Write Java program to check a String object of 5 characters is palindrome or not: (a) The comparison is case sensitive (b) The comparison is case insensitive
Create method addUserInput Write a method called addUserInput(). The method should ask the user to input...
Create method addUserInput Write a method called addUserInput(). The method should ask the user to input two integers (one by one), add the two integers, and return the sum. By using java.util.Scanner to get user input; The method may not compile due to Scanner Class which need to add a "throws" statement onto the end of the method header because some lines may throw exceptions Refer to the Java API documentation on Scanner to figure out which specific Exception should...
Write a recursive method to determine if a String is a palindrome. Create a String array...
Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. In Java
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then...
Programming Language : JAVA Create an interface named Turner, with a single method called turn(). Then create 4 classes: 1- Leaf: that implements turn(), which changes the color of the Leaf object and returns true. If for any reason it is unable to change color, it should return false (you can come up with a reason for failure). The new color can be determined at random. 2- Document: that implements turn(), which changes the page on the document to the...
IN JAVA: Implement an algorithm to check whether a LinkedList is a palindrome. 2 methods should...
IN JAVA: Implement an algorithm to check whether a LinkedList is a palindrome. 2 methods should be implemented: Constant space, i.e. without creating extra copies of the linked list Unrestricted space q1: / For this implementation you should use constant space   // Note: you are free to add any extra methods,   // but this method has to be used   public static boolean isPalindromeRestricted(ListNode head) {     // Your code goes here     return false;   } q2: // For this implementation the space...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
Write a recursive method to determine if a String is a palindrome. The program should contain...
Write a recursive method to determine if a String is a palindrome. The program should contain a String array that you can load several test cases to test your palindrome testing method. The program should load your String Array with the test data containing the possible palindromes from a text file. The program should test you application with a text file contained in your project folder After testing your program with your test cases in the text file, you program...
*****Using Java 1.         There is a class called Wages. It should have one method: calculateWages. This...
*****Using Java 1.         There is a class called Wages. It should have one method: calculateWages. This method accepts from a user (1) an integer hourly rate and (2) an integer total number of hours worked in a week. It calculates and displays the total weekly wage of an employee. The company pays straight time for the first 40 hours worked by an employee and times and a half for all the hours worked in excess of 40. This class should...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT