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.
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.
Write a program in Java to implement a recursive boolean function that returns True if the...
(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 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...
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 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 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 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 a palindrome, else false.
Implement a function that returns true if a String is Palindrome or false otherwise. A Palindrome is a String that reads from right and left the same. An empty String, and a String with one character are Palindrome. public static boolean isPalindrome (String str) {
Write a recursive method contains(int target, LLNode<Integer> list) that returns true if list contains target and false otherwise. For our example list contains(15, values) would return true while contains(10, values) would return false. (JAVA language)