-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessTheWord
More file actions
30 lines (25 loc) · 978 Bytes
/
Copy pathGuessTheWord
File metadata and controls
30 lines (25 loc) · 978 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
28
29
30
import java.lang.Math;
import java.util.Scanner;
public class GuessTheWord {
public static void main(String [] args){
String [] listOfWords = { "Programming", "Kotlin", "Java", "Coding" };
int randomIndex = (int)(Math.random() * listOfWords.length);
String randomWord = listOfWords[randomIndex];
for(int i = 0; i < randomWord.length(); i++){
if((int)(Math.random() * 2) == 0){
System.out.print(" _ ");
} else {
System.out.print(" " + randomWord.charAt(i) + " ");
}
}
System.out.println();
System.out.print("Guess The Word: ");
Scanner sc = new Scanner(System.in);
String guessedWord = sc.next();
if(guessedWord.equalsIgnoreCase(randomWord)){
System.out.println("Correct Answer!!!");
} else {
System.out.println("Wrong Answer!!!");
}
}
}