Koppelingen in nieuw tabblad openen
    • Werkrapport
    • E-mail
    • Herschrijven
    • Spraak
    • Titelgenerator
    • Slim antwoord
    • Gedicht
    • Opstel
    • Grap
    • Instagram-post
    • X-post
    • Facebook-post
    • Verhaal
    • Begeleidende brief
    • Hervatten
    • Taakbeschrijving
    • Aanbevelingsbrief
    • Ontslagbrief
    • Uitnodigingsbrief
    • Begroetingsbericht
    • Meer sjablonen proberen
  1. Hangman is a popular word guessing game where the player tries to guess a word by suggesting letters within a certain number of guesses. Below is a simple implementation of the Hangman game in Java.

    Example

    import java.util.Scanner;

    public class Hangman {
    private static String[] words = {"terminator", "banana", "computer", "cow", "rain", "water"};
    private static String word = words[(int) (Math.random() * words.length)];
    private static String asterisk = new String(new char[word.length()]).replace("\0", "*");
    private static int count = 0;

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    while (count < 7 && asterisk.contains("*")) {
    System.out.println("Guess any letter in the word");
    System.out.println(asterisk);
    String guess = sc.next();
    hang(guess);
    }
    sc.close();
    }

    public static void hang(String guess) {
    String newAsterisk = "";
    for (int i = 0; i < word.length(); i++) {
    if (word.charAt(i) == guess.charAt(0)) {
    newAsterisk += guess.charAt(0);
    } else if (asterisk.charAt(i) != '*') {
    newAsterisk += word.charAt(i);
    } else {
    newAsterisk += "*";
    }
    }

    if (asterisk.equals(newAsterisk)) {
    count++;
    hangmanImage();
    } else {
    asterisk = newAsterisk;
    }

    if (asterisk.equals(word)) {
    System.out.println("Correct! You win! The word was " + word);
    }
    }

    public static void hangmanImage() {
    if (count == 1) {
    System.out.println("Wrong guess, try again");
    System.out.println();
    System.out.println("___|___");
    }
    if (count == 2) {
    System.out.println("Wrong guess, try again");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println(" |");
    System.out.println("___|___");
    }
    // Add more stages as needed
    }
    }
    Gekopieerd.
    Feedback
  2. Hangman Game in Java - GeeksforGeeks

    12 jul. 2025 · This game is for beginners learning to code in Java and to give them a little brief about using strings, loops, and conditional statements. Understanding …

  3. Hangman Game in Java - Javacodepoint

    In this article, you will learn how to write the Hangman Game in Java. Hangman is a word-guessing game that involves two participants: the word-setter and the guesser. The game is usually played on …

  4. Mastering the Hangman Game in Java - javaspring.net

    16 jan. 2026 · Implementing the Hangman game in Java is a great way to learn and practice basic programming concepts. By understanding the fundamental concepts, usage methods, common …

  5. How to Create a Hangman Game in Java - CodeSpeedy

    This tutorial will show you how to create a hangman game in Java with the procedure. Everything is explained so that it can be easier to be understandable.

  6. Hangman Game in Java – Learn Programming

    11 dec. 2024 · In this Java implementation, we will create a simple console-based Hangman game where the user will be prompted to guess letters one by one. The game will track incorrect guesses …

  7. Hangman Game in Java - Full Tutorial (Beginning to End)

    16 jan. 2021 · This is a beginner friendly beginner's Java coding lesson tutorial, where we'll create a Hangman game completely from scratch, beginning to end. Learn or improve your Java by watching it...

    • Auteur: Coding with John
    • Weergaven: 62,6K
  8. Hangman Game Using Java Swing With Source Code

    Building a hangman game using Java is not only a fun project but also an opportunity to enhance your programming skills and gain a deeper …

  9. GitHub - OpenGenus/Hangman-Java: Hangman game in …

    This is a Hangman game implemented in Java Swing using Maven 3.8.1 and Java 18. The game allows players to guess letters to uncover a hidden word within a …

  10. Java Hangman Game - GitHub Pages

    This project is a Java implementation of the classic Hangman game. Players can guess letters to uncover a hidden word. The game includes features such as …

  11. Mensen vragen ook naar
    Loading
    Unable to load answer
  12. Verkrijg uitgebreide informatie over Hangman Game Java code