Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3452710
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:17:24+00:00 2026-05-18T09:17:24+00:00

I am having trouble finding pairs in a string of size five. So therefore,

  • 0

I am having trouble finding pairs in a string of size five. So therefore, there can only be two pairs. For every pair that I have found, I should increase the score by 2 points.
Here is what I have so far, but it is incorrect.

  String  temp = "4 5 4 3 3";
  String  tempLine = temp.replaceAll(" ", "");
  String[]  hand = temp.split(" ");
        for(int i = 0; i < hand.length; i++)
                  {

                      if(hand[i].equals(tempLine.substring(0, 1)) && i !=0 )
                          score += 1;
                      if(hand[i].equals(tempLine.substring(1, 2)) && i != 1 )
                          score += 1;
                      if(hand[i].equals(tempLine.substring(2, 3)) && i!= 2 )
                          score += 1;
                      if(hand[i].equals(tempLine.substring(3, 4)) && i!= 3)
                          score += 1;
                      if(hand[i].equals(tempLine.substring(4)) && i != 4)
                          score += 1;

                  }

EDIT: I am trying to find pairs in the hand that have similar value, for example 4 would be one pair found in this hand

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:17:25+00:00Added an answer on May 18, 2026 at 9:17 am

    I think this fits what you’re trying to do.

    char[] hand = {'a','b','c','b','c'};
    /* sort the hand to ensure pairs are next to each other */
    for(int x=0;x<hand.length - 1;x++){
        for(int y=(x+1);y<hand.length;y++){
            if((int)hand[x] > (int)hand[y]){
                char temp = hand[y];
                hand[y] = hand[x];
                hand[x] = temp;
            }
        }
    }
    int score = 0;
    for(int x=0;x<hand.length - 1;x++){
        if(hand[x] == hand[x + 1]){
            score++;
            /*if you want to make sure you only get pairs
              add an "x++;" that way it'll skip over the 
              letter you just tested*/
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble finding a regular expression that matches the following String. Korben;http://feeds.feedburner.com/KorbensBlog-UpgradeYourMind?format=xml;1 One
I'm having trouble finding documentation that makes me think that you can make requests
I'm having trouble finding an open-source IDE with support for Git. Are there any
I'm having trouble finding a list of the changes and bug fixes that have
I am having trouble finding a surefire to copy only visible cells from one
I'm having trouble finding books on the Windows Volume Shadow Copy Service. Can anyone
I'm having trouble finding information about how to use a model that doesn't belong
I am having trouble finding why the following XML won't deserialize. Message: There is
I'm having trouble finding the official home of the MercurialEclipse plugin (is there one?),
I'm having trouble finding a Yacc or Bison that doesn't require using darwinports for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.