0% found this document useful (0 votes)
41 views1 page

Adam Asmaca

This Java program implements a simple hangman game by randomly selecting a word from an array, converting it to a character array, and initializing a "mask" array to the same length with asterisks. It then prompts the user for input and checks each character of the word, replacing asterisks in the mask with correctly guessed letters until all letters are revealed or a maximum number of incorrect guesses is reached.

Uploaded by

mcsurmeli39
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views1 page

Adam Asmaca

This Java program implements a simple hangman game by randomly selecting a word from an array, converting it to a character array, and initializing a "mask" array to the same length with asterisks. It then prompts the user for input and checks each character of the word, replacing asterisks in the mask with correctly guessed letters until all letters are revealed or a maximum number of incorrect guesses is reached.

Uploaded by

mcsurmeli39
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class AdamAsmaca {

public static void main(String[] args) {


String[] kelimeler = {"kelime", "mobil", "java", "deneme"};

int ki = (int)(Math.random()*kelimeler.length);
char[] kelime = kelimeler[ki].toCharArray();

char[] maskeli = new char[kelime.length];


for (int i = 0; i < maskeli.length; i++) {
maskeli[i] = '*';
}
Scanner scanner = new Scanner(System.in);

int eksikHarf = kelime.length;

while(eksikHarf>0) {
char tahmin = scanner.next().charAt(0);
for (int i = 0; i < kelime.length; i++) {
if(kelime[i] == tahmin) {
eksikHarf--;
maskeli[i] = tahmin;

}
}
for (int i = 0; i < maskeli.length; i++) {
System.out.print(maskeli[i]);
}
System.out.println();
}

You might also like