Question: PLEASE HELP: Looking to make this code more efficient without losing functionality, just seeing if its possible, must utilize only recursion and one loop import

PLEASE HELP: Looking to make this code more efficient without losing functionality, just seeing if its possible, must utilize only recursion and one loop
import java.util.Scanner;
public class Assignment2{
public static void main(String[] args){
System.out.println("Enter the number of items to read");
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int[] a=new int[n];
System.out.println("Enter the numbers:");
for(int i=0;i=1 && n2>=1){
if(h1[n1-1]==h2[n2-1]){
f2=f2+1;
return findExact(h1,h2,n1-1,h2.length,f2);
}
else {
return findExact(h1,h2,n1,n2-1,f2);
}
}
return f2;
}
}
private static int findMirror(int[] h1, int[] h2, int n1, int n2,int f1){
if(f1==h1.length){
return f1;
}
else {
if(n1>=1 && n2>=1){
if(h1[n1-1]==h2[n2-n1]){
f1=f1+1;
return findMirror(h1,h2,n1-1,n2,f1);
}
else {
return f1;
}
}
return f1;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!