-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordGuessingGame.java
More file actions
27 lines (21 loc) · 890 Bytes
/
WordGuessingGame.java
File metadata and controls
27 lines (21 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
public class WordGuessingGame {
public static void main(String[] args) {
String hiddenWord = "programming";
Scanner scanner = new Scanner(System.in);
boolean isGuessed = false;
System.out.println("Welcome to the Word Guessing Game!");
System.out.println("Try to guess the hidden word.");
while (!isGuessed) {
System.out.print("Guess a word: ");
String userGuess = scanner.next().toLowerCase(); // Convert the guess to lowercase
if (userGuess.equals(hiddenWord)) {
isGuessed = true;
System.out.println("Congratulations! You guessed the correct word: " + hiddenWord);
} else {
System.out.println("Incorrect guess. Try again.");
}
}
scanner.close();
}
}