Question

Question: Concepts StringBuilder Var-Args Programming Assignment Palindrome Checker - A palindrome is a string that is...

Question:

Concepts

StringBuilder

Var-Args

Programming Assignment

Palindrome Checker - A palindrome is a string that is the same forwards as backwards. For example, the following strings are palindromes:

" ", "a", "aa", "bb", "aba", "bab", "bob"

These are not:

"ab", "ba", "bba", "abb"

Use StringBuilder concept to create a palindrome checker. The method will be called palindromChecker and it will use the var-arg concept to accept 1 to many Strings. The class name for this program is Palindrome.

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

Solution for the given questions are as follows -

Code :

import java.util.*;
class Palindrome
{
   // palindromChecker variable number of String arguments.
   // a is Var-Args
   static void palindromChecker(String ...a)
   {
   // declaring two StringBuilder objects to store strings
   StringBuilder palindrome = new StringBuilder();
   StringBuilder notpalindrome = new StringBuilder();
   //for loop over strings arguments
       for (String i: a) {
       // creating StringBuilder object
       StringBuilder str = new StringBuilder(i);
       // reverse String
       StringBuilder reverseString = str.reverse();
       // convert StringBuilder to String
       String rev =reverseString.toString();
       // check string is palindrome or not and append strings to StringBuilder objects
           if (i.equals(rev)) {
           palindrome.append(i + " ");
           } else {
           notpalindrome.append(i + " ");
           }
       }
       // print the final results
       System.out.println("Palindrome Strings : "+ palindrome);
       System.out.println("Not Palindrome Strings : "+ notpalindrome);
   }
   public static void main(String args[])
   {
       // palindromChecker ("aba");       // one parameter
       // palindromChecker ("aba", "dvd"); // two parameter
       palindromChecker ("abc","ab","madam","mno"); // four parameters
   }
}

Code Screen Shot :

Output :

Add a comment
Know the answer?
Add Answer to:
Question: Concepts StringBuilder Var-Args Programming Assignment Palindrome Checker - A palindrome is a string that is...
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
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