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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:30:35+00:00 2026-06-14T06:30:35+00:00

This is my first question on this site so i’ll try not to be

  • 0

This is my first question on this site so i’ll try not to be a total noob..

I’m currently creating hangman game in java.
So my question to you is if we are given a word “ghost”
and ghost is replaced with “_ “,

hiddenWord = ghost.length();
for (i=0; i < ghost.lenth(); i ++)
System.out.print("_ ")

giving us an output of

“_ _ _ _ _ “

Lets say we guess the letter “O”
the letter “o” is guessed, how do i replace `

"_ _ _ _ _" with 
"_ _ o _ _ "

my current class file

public void pickWord()
    {
        String[] listOfWords;
        listOfWords = new String[10];
        listOfWords[0] = "shenanigans";
        listOfWords[1] = "conversely";
        listOfWords[2] = "octopus";
        listOfWords[3] = "dizzy";
        listOfWords[4] = "malicious";
        listOfWords[5] = "goosebumps";
        listOfWords[6] = "flying";
        listOfWords[7] = "staff";
        listOfWords[8] = "xylophone";
        listOfWords[9] = "zapping";
        Random generator = new Random();
        int lineNumber = generator.nextInt(9);
        disguisedWord = listOfWords[lineNumber];


    }   
    public void displayMark()
    {
        for( int i = 0; i < disguisedWord.length(); i ++)
            underscore = underscore + "_ ";
        System.out.println(underscore);

    }
    public void makeGuess() throws IOException
    {
        System.out.println("Your word is " + disguisedWord.length() + " letters long.");
        System.out.println("Feel free to guess a letter.");
        guess = (char)System.in.read();
  • 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-06-14T06:30:37+00:00Added an answer on June 14, 2026 at 6:30 am
    String ghost = "ghost";
    String input = "o";
    for (int i = 0; i < ghost.length(); i++) {
        if (String.valueOf(ghost.charAt(i)).equalsIgnoreCase(input)) {
            System.out.print(input + " ");
        } else {
            System.out.print("_ ");
        }
    }
    

    You can simplify the if statement using the ternary operator:

    System.out.print(String.valueOf(ghost.charAt(i)).equalsIgnoreCase(input) ? input + " " : "_ ");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question to SO so i'll try not to disgrace myself.
This is my first question on the site and I hope it's not too
This is my first question, but I've already found this site extremely helpful, so
This is my first question. Thanks to everyone who contributes to this site, it's
this is my first question.. so, here we go. i have a site, 100%
though I have visited this site many times, this is my first question. After
this is my first question here so be gentle ! recently i try to
This is my first question on this site, having used it many times to
This is my first question on the site even though i have been coming
this is my first question, but i use this site a lot this last

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.