|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
|
2
|
+import java.util.*;
|
|
3
|
+/**
|
|
4
|
+ * This program will do the following:
|
|
5
|
+ * Firstly ask the user to input his/her name. Then find a way to check the person's name to see if it is Bob or Alice.
|
|
6
|
+ * If the user's name is either Alice or Bob; then a greeting will be printed to the screen.
|
|
7
|
+ */
|
|
8
|
+public class AliceAndBob {
|
|
9
|
+ /* The Scanner class is used as a simple text scanner which can parse/analyze a sentence in parts.
|
|
10
|
+ * In this case Scanner is used to scan the user's input to check for something specific.
|
|
11
|
+ *System.out.print ("What is your name?"); ---> this prints "What is your name?" to the console and this prompts the user to input his/her name.
|
|
12
|
+ * String name = in.nextLine---> this will print the entire line that that the user enters.
|
|
13
|
+ */
|
|
14
|
+ public static void main(String[] args ){
|
|
15
|
+ Scanner in = new Scanner(System.in);
|
|
16
|
+
|
|
17
|
+ System.out.print("What is your name?");
|
|
18
|
+ String name = in.nextLine();
|
|
19
|
+
|
|
20
|
+ //If the user's name is equivalent to Alice or Bob; then print "Hi!"
|
|
21
|
+
|
|
22
|
+ if(name.equals("Alice") || name.equals("Bob")){
|
|
23
|
+ System.out.println("Hi!");
|
|
24
|
+
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ }
|
|
28
|
+
|
|
29
|
+}
|