
Compare 5 numbers
Hey i need to write the method where i have to compare 5 numbers Basicly this is a game and we have got
1 of a kind  0 points
3 of a kind  3 points
4 of a kind  4 points
5 of a kind  5 points
So on if i have 3 the same numbers then i need to display 3, for 4 the same numbers 4 and for 5 numbers 5 like above. So my method luks like:
private int getHowManyMatch(int numberToMatch, int d1, int d2, int d3, int d4, int d5) {
int numberOfMatches = 0;
return numberOfMatches;
}
Thx a lot.

Hi,
Can you give some more details.
What is the value of numberToMatch and d1,d2....., in method getHowManyMatch().
what i understand is :
you have :
1 of a kind  0 points
2 of a kind  1 points
3 of a kind  3 points
4 of a kind  2 points
5 of a kind  5 points
the out put of this sample will be : 2
You will pass points to getHowManyMatch as d1,d2....d5, and number to match will be 1 , 2 ,3
sanjeev

5, 6, 6, 1, 6
6, 5, 5, 5, 5
3, 3, 3, 3, 3
5, 2, 5, 1, 6
1, 2, 3, 4, 5
You see the first line you've got 3 X 6 so i have to print 3 because for 3 the same numbers i've got 3 points. Second line 4 x 5 so i've got 4 points so i need to print 4. Third line 5 x 3 so i've got 5 point and need to print 5. I need to print number of matches.

Ok
so you need to pass 5*5 matrix and then get result.
sanjeev

something like that. just get number of matches if i have not matches print 0 , two matches print 2, three matches print 3 , four matches print 4 , five matches print 5.

The first chunk of code will go through and find what number has the most and then return how many of that number exist, but if you want to search for a specific number the second piece of code will do the trick. Either way they are both there for you.
Code:
int getHowManyMatch(int d1, int d2, int d3, int d4, int d5) {
int numberOfMatches = 0;
int[] darray = { d1, d2, d3, d4, d5 };
int temp;
for (int x = 0; x < 5; x++) {
temp = 0;
for (int y = 0; y < 5; y++) {
if (darray[x] == darray[y]) {
temp++;
}
if (temp > numberOfMatches) {
numberOfMatches = temp;
}
}
}
return numberOfMatches;
}
Code:
int getHowManyMatch(int numberToMatch, int d1, int d2, int d3, int d4,
int d5) {
int numberOfMatches = 0;
int[] darray = { d1, d2, d3, d4, d5 };
for (int y = 0; y < 5; y++) {
if (numberToMatch == darray[y]) {
numberOfMatches++;
}
}
return numberOfMatches;
}