Can a MongoDB key have two arrays?

Java method to check two int arrays to see if they are mirror images?

  • Can't seem to figure this out. Question is: Create a method called mirrorImage, which takes two integer arrays as input parameters. You may assume that the two actual parameters have the same length. Your method should return true if the arrays are the reverse of each other. Otherwise mirrorImage should return false. public boolean mirrorImage (int [ ] data1, int [ ] data2) { //CODE }

  • Answer:

    Not sure if this is the most effective way but, give it a try public boolean mirrorImage (int [ ] data1, int [ ] data2) { boolean answer=true; //--------------------------------------… /*In case the lenght of each array is different, it will take the smallest array as the limit for the next step so theres no error while incrementing*/ int x=data1.length; int z=data2.length; int limit=0; if(x<z){ limit=x; }else{ limit=z;// z is equal or less than x } /*if u know both arrays are the same just set, int limit=data1.length; so u dont have to wrttie all this*/ //--------------------------------------… for(int index=0;index<limit;index++){ //if any of the data its not the same it will return a false if(data1[index]!=data2[index]){ answer=false; } } return answer; }

Kevin at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Do something like: if (data1.length != data2.length) return false; for (int i = 0, j = data1.length; i == data1.length; i++, j--) if (data1[i] != data2[j]) return false; return true; You might need to revise it slightly to be accurate Java code.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.