Question

Write a program in Java to implement a recursive boolean function that returns True if the...

Write a program in Java to implement a recursive boolean function that returns True if the given array contents remain the same when the array is reversed. Otherwise function must return False.

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

Java Code:

import java.io.*;

class Main {

static boolean palindromicArray(int a[],int i,int j)

{

if(i>=j) {

return true;

}

if(a[i]==a[j]) {

return palindromicArray(a,i+1,j-1);

}

else

return false;

}

public static void main (String[] args) {

int a[] = { 1,2,3,2,1};

if (palindromicArray(a,0,a.length-1))

System.out.print( "Array is same when reversed");

else

System.out.println( "Array is not same when reversed");

}

}

if you like the answer please provide a thumbs up.

Add a comment
Know the answer?
Add Answer to:
Write a program in Java to implement a recursive boolean function that returns True if the...
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
  • (Java) - Write a recursive program that takes array of number and an integer, and returns...

    (Java) - Write a recursive program that takes array of number and an integer, and returns true if the integer is in the array or false if the integer is not in the array

  • (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int...

    (a) Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1. The terSearch search function, unlike the binary search, must consider two dividing points int d1 = l + (r - l)/3 int d2 = d1 + (r - l)/3 For the first call of your recursive search function...

  • write a recursive function that returns true if the digits of a positive integer are in...

    write a recursive function that returns true if the digits of a positive integer are in increasing order ; otherwise, the function returns false. Also write a program to test your function.

  • Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters...

    Using Java: 1. Recursive Multiplication Write a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times y. Remember, multiplication can be performed as repeated addition as follows: 5×6=6+6+6+6+6 2. Recursive findings Write a recursive boolean method named reFinding. The method should search an array for a specified value, and return true if the value is found in the array, or false if the value is not found in...

  • Java question Write the method reversed that returns true if and only if the arrays a...

    Java question Write the method reversed that returns true if and only if the arrays a and b contain exactly the same elements, but in reversed order. For example, reversed ({3, 1}, {1, 3}) returns true, but reversed ({3, 1}, {2, 3}) and reversed ({3, 1}, {1, 1, 3}) both return false. public static boolean reversed (int [] a, int [] b) should return true if and only if a and b contain the same elements, reversed.

  • Write a method booleanisValid() that takes a list of 3 boolean values as argument and returns...

    Write a method booleanisValid() that takes a list of 3 boolean values as argument and returns true if any of the entries in the array is true, and false otherwise. This can be done in 4 lines (2 of the lines are { and }   )               Fill in the Solution:                              public static boolean isValid(______ _______, ______ _______, ______ _______)                              {                                 return(true);                              } Java language, thank you.

  • Write a C++ program that does the following : 1. Accepts array size from the keyboard....

    Write a C++ program that does the following : 1. Accepts array size from the keyboard. The size must be positive integer that is >= 5 and <= 15 inclusive . 2. Use the size from step 1 in order to create an integer array. Populate the created array with random integer values between 10 and 200. 3. Display the generated array. 4. Write a recursive function that displays the array in reverse order . 5. Write a recursive function...

  • Write a program that write a value-returning function, isVowel, that returns the value true if a...

    Write a program that write a value-returning function, isVowel, that returns the value true if a given character is a vowel and otherwise returns false. You must insert the following comments at the beginning of your program and write our commands in the middle: Write a C++ Program: /* // Name: Your Name // ID: Your ID */ using namespace std; #include <iostream> using namespace std; bool isVowel(char ch); int main() {     char ch;     …     …         ...

  • Write a recursive method,     public static Boolean isPalindrome(String s) That returns true if s is...

    Write a recursive method,     public static Boolean isPalindrome(String s) That returns true if s is a palindrome, else false.


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