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 7028189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:21:15+00:00 2026-05-28T00:21:15+00:00

I am learning Java and in the process I am writing a Word Guess

  • 0

I am learning Java and in the process I am writing a Word Guess game.
Now mine problem is the following:

Assume the word to guess is “lingo”. And assume “oodle” is a word you suggested.
On processing your guess, the following should be output:
Correct Letters: none
Wrong Position Letters: ‘o’ at first position, ‘l’ at fourth position
Note that the second ‘o’ should not be mentioned as a letter in the wrong position, as we already have reported an ‘o’ prior to that. So if you enter ‘ooooo’, only the last letter should be highlighted as it is in the correct position, and if you enter ‘ooooz’, only the first letter should be highlighted, and not the other ‘o’s.

I have tried some solutions but all seem to fail. I know there is a smart/not so complex way to do this. So could anyone help me with that?

The code:

// / Indicates whether a letter has been accounted for
// / while highlighting letters in the guess that are not
// / in the correct position
private Boolean[][] marked = new Boolean[WordLength][5];

// / Holds which all letters have been solved so far
private Boolean[][] solved = new Boolean[WordLength][6];


public void CheckLetters() {

    for (int j = 0; j < currentAttempt; j++) {
        tempWord = list.get(j); //The guessed words

        for (int i = 0; i < WordLength; i++) {

            if (tempWord.charAt(i) == CurrentPuzzleWord.charAt(i)) {
                solved[i][j] = true; //CurrentPuzzleWord is the string with the hidden word

            } else if (CurrentPuzzleWord.indexOf(tempWord.charAt(i)) != -1) {
                marked[i][j] = true;
            }
        }
    }
  • 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-28T00:21:15+00:00Added an answer on May 28, 2026 at 12:21 am

    So you are going to want to do multiple checks.

    String oracle = "lingo";
    String input = "oodle";
    String modOracle = "";
    // ArrayList for noting the matched elements
    ArrayList<Integer> match = new ArrayList<Integer>();
    // ArrayList for the correct letters with wrong position
    ArrayList<Integer> close = new ArrayList<Integer>();
    // Length of the Strings of interest
    int length = oracle.length;
    

    The first thing you want to check, obviously, is for letters that are a match and in the right position. So take the oracle string and the user input string and compare them character by character, noting the ones that are correct.

    // may need to check that oracle and input are same length if this isn't enforced.
    for (int i = 0; i < length; i++) {
        if (input.substring(i,i+1).equals(oracle.substring(i,i+1))) {
            // there is a match of letter and position
            match.add(i);
        }
        else
            modOracle = modOracle + oracle.substring(i,i+1);
    }
    

    You will then need to do a second check for letters that are correct but in the wrong position. To do this, first take the correct letters from the previous check out of the running. Then for each letter in the input string that matches a letter in the oracle string, note the match and remove it from the rest of the check. Continue this until the entire input string has been looked through.

    for (int i = 0; i < length; i++) {
        if (match.contains(i))
            continue;
    
        // String to match
        String toMatch = input.substring(i,i+1);
    
        for (int j = 0; j < modOracle.length; j++) {
            if (toMatch.equals(modOracle.substring(j,j+1))) {
                close.add(i);
                // then remove this letter from modOracle
                // need small utility method for this.
                break;
            }
        }
    }
    

    Combine the results of the two checks and output them to the user.

    I am not sure how you want to display the results to the user, but you now have the arraylist match which corresponds to the positions in oracle/input that are completely correct and the arraylist close which corresponds to the positions in oracle/input such that the letter appears somewhere, but not at that position.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What does public static void mean in Java? I'm in the process of learning.
Well..I am learning java now and I am curious to know will this yield
I am in the process of learning Java and the book I am using
Im learning Java and Im creating a memory type game where you have to
When I was learning Java coming from a background of some 20 years of
I am learning Java for a test (tomorrow) and am wondering about a question
So I'm learning java, and I have a question. It seems that the types
I'm learning Java (and OOP) and although it might irrelevant for where I'm at
I am learning Java, theres one thing I do not understand.. in the main
I'm learning Java, and I know one of the big complaints about newbie programmers

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.