Quote:
Originally Posted by Go_Blue
I am working on an assignment from last semester as practice before classes start. I'm trying to do it in a different way than I did last time. Does anyone know why this isn't working? By isn't working I mean the output is incorrect.
The goal of the code is to say whether two sequences of numbers are identical.
CODE
I also interpret it in a different way. But assuming two sets have to be same:
Colors.sameNumber(int nums[ ], int nums2 [ ]):
nums={2,2,3} and nums2={2,3,2} returns false (fault).
nums={2,3} and nums2={5,2} returns true (fault).
You see why?
Quote:
Originally Posted by Go_Blue
edit- last time I used a counter in the boolean method. shouldn't the break statement work just as well though? the way i understand it, if a number in nums2 matches up with a number in nums 1, then it will break and go back to the top. if the next number in nums2 matches up with a number in nums1, then it will break and go back to the top, etc. until it returns true. if a number ever does not match up, then it will skip down to return false.
this is how i did it last time:
CODE
Colors.sameNumber(int nums[ ], int nums2 [ ]):
nums={2,2,3} and nums2={3,2,2} returns false (fault).
nums={2,2,4,3} and nums2={5,6,2,2} returns true (fault).
You see why?
You've a correct implementation now? You have several possible solutions, including some fancy tricky ones:
You could multiply every digit in each array with a certain number (differs from digit to digit and should be chosen carefully), after adding the results together (seperate for both arrays) this gives two integers which need to be equal.