java - Finding matching numbers in two arrays -
hey i'm trying write method compares 2 arrays , returns number of values have in common.
for example, if there 2 arrays:
arr{0,4,2,5} arr1{0,7,4,4}
then method homecoming 2.
this have far:
public int numdigitscorrect(permutation other) { int c=0; for(int i=0; i<nums.length; i++) { for(int x=0; x<nums.length;x++) { if(nums[i]==other.nums[x]) { system.out.println(nums[i] + " " + other.nums[x] + " "); c++; } } } homecoming c; }
you need alter in current function mention below :
public int numdigitscorrect(permutation other) { int c=0; for(int i=0; i<nums.length; i++) { for(int x=0; x<other.length;x++) { if(nums[i]==other[x]) { system.out.println(nums[i] + " " + other[x] + " "); c++; } } } homecoming c; }
i assume nums
, other
int arrays shown below
int[] nums = {0,4,2,5}; int[] other = {0,7,4,4};
java arrays oop
No comments:
Post a Comment