Results 1 to 6 of 6
Thread: Compare 5 numbers
 04152008, 09:29 AM #1Member
 Join Date
 Apr 2008
 Posts
 4
 Rep Power
 0
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.
 04152008, 09:48 AM #2
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
 04152008, 09:58 AM #3Member
 Join Date
 Apr 2008
 Posts
 4
 Rep Power
 0
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.
 04152008, 10:26 AM #4
Ok
so you need to pass 5*5 matrix and then get result.
sanjeev
 04152008, 10:46 AM #5Member
 Join Date
 Apr 2008
 Posts
 4
 Rep Power
 0
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.
 04152008, 07:04 PM #6
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.
Java 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; }
Java 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; }
Similar Threads

How to Compare two Dates
By Java Tip in forum java.utilReplies: 1Last Post: 06242008, 07:05 AM 
Compare lists
By JavaNoob in forum New To JavaReplies: 2Last Post: 08082007, 03:11 PM 
how to compare two strings
By elizabeth in forum New To JavaReplies: 7Last Post: 08062007, 03:57 AM 
Compare 2 XML
By Peter in forum XMLReplies: 1Last Post: 07052007, 02:58 AM 
compare speed
By bbq in forum JDBCReplies: 1Last Post: 06282007, 05:34 PM
Bookmarks