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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:11:04+00:00 2026-05-26T07:11:04+00:00

**Hello, I have to create a hangman game in java. I cant use arrays.

  • 0

**Hello, I have to create a hangman game in java. I cant use arrays. Most of my code is done but I have been having some problems and some tips would be welcome.


I just found something else that I could use help on. After prompting the user for a new secret word and using newHangMan.setSecretWord(newWord); my disguised word does not reset to “????” (with the same number of “?” as words in the secret word).


I’m very sorry for such a long post and the bad formatting(1st time posting here).
Can anyone help?**

This is my class file:

 public class HangMan 
{

private String secretWord = "bigbang",  disguisedWord = "";
private int guessCount = 0, missCount = 0;



public void setSecretWord(String newWord)
{
    secretWord = newWord;
    guessCount = 0;
    missCount = 0;

    int wordLength = newWord.length();
    while(wordLength > 0)
    {
        disguisedWord = disguisedWord + "?";
        wordLength--;
    }

}

public String getSecretWord()
{
    return secretWord;
}




 public boolean isFound()
 {  
    return secretWord.equalsIgnoreCase(disguisedWord);

 }


 public String getDisguisedWord()
 {
     return disguisedWord;
 }

 public int getGuessCount()
 {
     return guessCount;
 }

 public int getMissesCount()
 {
     return missCount;
 }

 public void guessCharacter(char c)
 {
    // int position = secretWord.indexOf(c);
     boolean got_it = false;
     String updateDisguised="";

     for(int i=0; i < secretWord.length();i++)
     {

         if(c == secretWord.charAt(i))
         {

             updateDisguised = updateDisguised + secretWord.charAt(i);

             String checkDuplicate = updateDisguised.substring(0,i);
             int duplicatePos = checkDuplicate.indexOf(c);
             if(duplicatePos <0)
                 guessCount++;
             got_it = true;


         }
         else 
         {
             updateDisguised = updateDisguised + disguisedWord.charAt(i);
         }

     }
     if(got_it == false)
     {
         missCount++;
         guessCount++;
     }


     disguisedWord = updateDisguised; 

 }










 }

This is my main method:

import java.util.Scanner;



 public class HangManGame {

public static void main(String[] args) 
{


    boolean retry= true;
    String retry_ans;

    Scanner kb = new Scanner(System.in);


    HangMan newHangMan = new HangMan();

    String word = newHangMan.getSecretWord();
    String input;
    char guess;
     newHangMan.setSecretWord(word);

    System.out.println("Hangman game starts:");

do{


    System.out.println("Guess this: " + newHangMan.getDisguisedWord());
    System.out.println("Enter your guess character: [guess]");
    input = kb.next();
    guess = input.charAt(0);

    newHangMan.guessCharacter(guess);

    System.out.println(newHangMan.getDisguisedWord());

    System.out.println("Number of guesses so far : " + newHangMan.getGuessCount());
    System.out.println("NUmber of misses so far: " + newHangMan.getMissesCount());




    if((newHangMan.getMissesCount()==7) || (newHangMan.isFound()))
    {
        System.out.println("The game is over");

        System.out.println("Would you like to try again?");
        retry_ans = kb.next();
        if(retry_ans.equalsIgnoreCase("yes"))
        {
            retry = true;
            System.out.println("Please enter a new secret word:");
            String newWord = kb.next();
            newHangMan.setSecretWord(newWord);
        }
        else
        {
            retry =false;
        }

    }






    }   while(retry == 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-26T07:11:04+00:00Added an answer on May 26, 2026 at 7:11 am
    (newHangMan.isFound()=true)
    

    should be

    newHangMan.isFound()
    

    Do not make an bool compare to another bool.
    The = is evaluate the boolean.

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

Sidebar

Related Questions

I want to unit test my code which will have to create a .java
i have to create connecting server<=>client. I use this code: Server: import socket HOST
Hello I have this code where i create an xlsx file and i need
I have been using TCPDF for sometime. It's simple to use, outputs low size
Hello guys I have a confusing question! If I'm using WCF to create a
Hello I have a jquery function called create time box This creates a textbox
Hello I have $string1, Array[] and $string2. I want to create a Arraynew[] such
Hello I have the following in my Create Controller: def create @requestable = find_requestable
Hello I'm have a task - create script, what will walk in internet and
Hello I have a gridView which I use to show some pictures on (small

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.