import java.util.
*;
class Guessmybrief{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] words = {"", "yellow", "pink", "red", "blue"};
Random random = new Random();
int index = random.nextInt(words.length);
String word = words[index];
String hidden = new String(new char[word.length()]).replace('\0', '*');
int attempts = 1;
boolean guessed = false;
System.out.println("Guess the color of my brief,yellow,pink,red,blue, You
have 3 attempts.");
while (!guessed && attempts < 3) {
System.out.println(hidden);
System.out.print("Guess a letter: ");
char guess = input.next().charAt(0);
if (word.indexOf(guess) == -1) {
attempts++;
System.out.println("Wrong guess! You have " + (4 - attempts) + "
attempts left.");
} else {
char[] hiddenArray = hidden.toCharArray();
for (int i = 0; i < word.length(); i++) {
if (word.charAt(i) == guess) {
hiddenArray[i] = guess;
}
}
hidden = String.valueOf(hiddenArray);
}
if (hidden.equals(word)) {
guessed = true;
System.out.println("Congratulations! You guessed the color of my
brief word: " + word);
}
}
if (!guessed) {
System.out.println("Sorry, wala na!! ang sagot kasi ay " + word);
}
}
}