Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2008, 10:29 AM
Member
 
Join Date: Apr 2008
Posts: 4
Snowboardmylife is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-15-2008, 10:48 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
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

Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 10:58 AM
Member
 
Join Date: Apr 2008
Posts: 4
Snowboardmylife is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-15-2008, 11:26 AM
sanjeevtarar's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Delhi(India)
Posts: 249
sanjeevtarar is on a distinguished road
Ok

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


sanjeev
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 04-15-2008, 11:46 AM
Member
 
Join Date: Apr 2008
Posts: 4
Snowboardmylife is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 04-15-2008, 08:04 PM
Chris.Brown.SPE's Avatar
Member
 
Join Date: Apr 2008
Location: State College, PA
Posts: 50
Chris.Brown.SPE is on a distinguished road
Send a message via AIM to Chris.Brown.SPE
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; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Compare two Dates Java Tip java.util 1 06-24-2008 08:05 AM
Compare lists JavaNoob New To Java 2 08-08-2007 04:11 PM
how to compare two strings elizabeth New To Java 7 08-06-2007 04:57 AM
Compare 2 XML Peter XML 1 07-05-2007 03:58 AM
compare speed bbq Database 1 06-28-2007 06:34 PM


All times are GMT +3. The time now is 06:22 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org