Question

Pleas write a program that checks if any array of string is a plaindrome required input:...

Pleas write a program that checks if any array of string is a plaindrome

required input:

isPalindrome("dog","dog","cat","cat") ---> false
isPalindrome("a","tree","tree","a" ---> true;
isPalindrome("a","b","train","b","a") ---> true

this needs to be written in java

Homework Answers

Answer #1

Solution for the given question are as follows -

Code :


class ArrayPalindrome {
// checkPalindrome is a Recursive function check array is Palindrome or Not
static int checkPalindrome(String arr[], int start, int end)
{
   if (start >= end) {
       return 1;
   }
   if (arr[start] == arr[end]) {
       return checkPalindrome(arr, start + 1, end - 1);
   }
   else {
       return 0;
   }
}
   public static void main (String[] args) {
String arr[] = { "dog","dog","cat","cat" };
   // String arr[] = { "a","tree","tree","a" };
   // call to checkPalindrome() function
int result = checkPalindrome(arr, 0, arr.length - 1);
   if (result == 1)
       System.out.print( "Array Is Palindrome");
   else
       System.out.println( "Array Is Not Palindrome");
   }
}

Code Screen Shot :

Output :

Know the answer?
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
Similar Questions
C++ program checks if an input string is a palindrome or not. Ignore case and remove...
C++ program checks if an input string is a palindrome or not. Ignore case and remove all non-alphanumeric characters in the input string. C++ program uses only one string (no extra-string or array). And also, use two indices to point from the beginning and ending positions. Sample Input 0 Race car Sample Output 0 TRUE Sample Input 1 7...8 Don't nod 78. Sample Output 1 FALSE
Write a C++ program that checks whether a binary search tree is an AVL. The input...
Write a C++ program that checks whether a binary search tree is an AVL. The input is an arbitrary binary search tree, and the output is binary, so either true or false.
public class PalindromeChecker { /** * Method that checks if a phrase or word is *...
public class PalindromeChecker { /** * Method that checks if a phrase or word is * a Palindrome * * @param str * Represents a string input * * @return true * True if the string is a Palindrome, * false otherwise */ public static boolean isPalindrome(String str) { if (str == null) { return false; } str = str.toLowerCase(); String temp = ""; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if ((ch...
c++ 1. Write a program that takes in a string as an input of any size...
c++ 1. Write a program that takes in a string as an input of any size and replaces all vowel letters in the string with an ‘x’. You must use Logical Operators and implement it using a user-defined function.
Write a matlab program that takee a character (a-z) as an input and checks if that...
Write a matlab program that takee a character (a-z) as an input and checks if that is a vowel or not using switch statment? If the user inputs any other character, the program should display a proper error message.
Java Lab Assignment Write a method called convertToString. The method will take an array of chars...
Java Lab Assignment Write a method called convertToString. The method will take an array of chars as an argument and it will return a String. Each index of the array will be part of the each index of the String. method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for *...
Java Lab Assignment Write a method called convertToArray. The method will take a String as an...
Java Lab Assignment Write a method called convertToArray. The method will take a String as an argument and it will return an array of chars. Each index of the String will be stored in each index of the array. method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for * @return...
Java Lab Assignment Write a method named findMax. The method will take an array of doubles...
Java Lab Assignment Write a method named findMax. The method will take an array of doubles as an argument, and it will return the largest value in the array. (Note, you will have to create a new array of doubles) . method must be well documented using JavaDoc, example: /** * The find method checks if the target in the array * @param String [] a - array of Strings * @param String t - value to be searched for...
Write a java script function that accepts integer array, searchKey as input, display True if the...
Write a java script function that accepts integer array, searchKey as input, display True if the value is found in the array, else display False. it done html and javascript and plz do it in simple way
Write a program that accepts an input string from the user and converts it into an...
Write a program that accepts an input string from the user and converts it into an array of words using an array of pointers. Each pointer in the array should point to the location of the first letter of each word. Implement this conversion in a function str_to_word which returns an integer reflecting the number of words in the original string. To help isolate each word in the sentence, convert the spaces to NULL characters. You can assume the input...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT