-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathMain.java
More file actions
41 lines (31 loc) · 1.43 KB
/
Main.java
File metadata and controls
41 lines (31 loc) · 1.43 KB
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
31
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
String question = "Say my name!";
String choiceOne = "Willie Wonka";
String choiceTwo = "Woodrow Wilson";
String choiceThree = "Walter White";
String correctAnswer = choiceThree;
// Write a print statement asking the question
System.out.println(question);
// Write a print statement giving the answer choices
System.out.println(choiceOne);
System.out.println(choiceTwo);
System.out.println(choiceThree);
Scanner input = new Scanner(System.in);
// Have the user input an answer
// Retrieve the user's input
String userAnswer = input.next();
input.close();
// If the user's input matches the correctAnswer...
// then the user is correct and we want to print out a congrats message to the user.
if(userAnswer.equals(correctAnswer)) {
System.out.println("Congrats! You have choosen the correct answer!!!");
};
// If the user's input does not match the correctAnswer...
// then the user is incorrect and we want to print out a message saying that the user is incorrect as well as what the correct choice was.
if(!userAnswer.equals(correctAnswer)) {
System.out.println("You failed!!!");
}
}
}