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