Question & Answer: bool equivalent (int a[], int b[], int n){…..

bool equivalent (int a[], int b[], int n){
int count;
int keepgoing=0;
int temp; // to move last digit to first position
while (keepgoing<n){ // while loop to cycle
count=0;
for(int j=0; j< n; j++){ // for loop to test for =
if (a[j]==b[j]) count++;
else break;
}// for loop close
if (count ==n){ return true;}
temp=b[n-1];
for( int q= n-1; n>0; n–){ // for loop to shift elements to the right
b[q]= b[q-1];
}
b[0]= temp;

keepgoing++;
}
return false;
}

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: bool equivalent (int a[], int b[], int n){…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

Program:

import java.io.*;

class AB // Here we are taking class name as AB
{
boolean equivalent (int a[], int b[], int n){
int count;
int keepgoing=0;
int temp; // to move last digit to first position
while (keepgoing<n){ // while loop to cycle
count=0;
for(int j=0; j< n; j++){ // for loop to test for
if (a[j]==b[j]) count++;
else break;
}// for loop close
if (count ==n){

return true;

}

temp=b[n-1];
for( int q= n-1; n>0; n–){ // for loop to shift elements to the right
b[q]= b[q-1];
}
b[0]= temp;
keepgoing++;
}
return false;
}
public static void main(String args[])
{
AB a=new AB();
int count1=0,num=1;
if(count1 ==num ){
System.out.println(“True”);}
else
System.out.println(“False”);
}
}

Output: