Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default 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.

  2. #2
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    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


  3. #3
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    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.

  4. #4
    sanjeevtarar's Avatar
    sanjeevtarar is offline Senior Member
    Join Date
    Apr 2008
    Location
    Jaipur(India)
    Posts
    318
    Rep Power
    7

    Default

    Ok

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


    sanjeev

  5. #5
    Join Date
    Apr 2008
    Posts
    4
    Rep Power
    0

    Default

    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.

  6. #6
    Join Date
    Apr 2008
    Location
    Fort Wayne, Indiana
    Posts
    62
    Rep Power
    0

    Default

    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

  1. How to Compare two Dates
    By Java Tip in forum java.util
    Replies: 1
    Last Post: 06-24-2008, 07:05 AM
  2. Compare lists
    By JavaNoob in forum New To Java
    Replies: 2
    Last Post: 08-08-2007, 03:11 PM
  3. how to compare two strings
    By elizabeth in forum New To Java
    Replies: 7
    Last Post: 08-06-2007, 03:57 AM
  4. Compare 2 XML
    By Peter in forum XML
    Replies: 1
    Last Post: 07-05-2007, 02:58 AM
  5. compare speed
    By bbq in forum JDBC
    Replies: 1
    Last Post: 06-28-2007, 05:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •